Use wio_open and wio_close where needed to avoid blocking
Use wio_glob instead of the blocking glob

Also fix memory leak by calling globfree.