rewrite getWorkingDirectory to use allocaBytes for exception safety

Currently, the implementation of `getWorkingDirectory` uses `mallocBytes`/`free` directly, without `bracket` or `allocaBytes`. Therefore it will leak space in the event of an (asynchronous) exception.