Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
local: harden local_close() and use it for local_open() failure
There's a bug, when enabling a buffer (with local_buffer_enabled_set(), i.e. writing to 'buffer/enable'), we can get -EINVAL, because the scan_mask is invalidated by the kernel. The issue seems to be that the local_open() exit-on-failure path is un-balanced. Some things don't seem to be cleaned-up on exit-on-failure. This is seen with iiod trying to open a high-speed buffer device, where the exit-on-failure path does not call munmap() on the buffers, nor does it free the memory allocated for the buffer (in libiio). On the next retry/open the buffer device is locked and -EBUSY is returned. Essentially, this leaks resources (a file-descriptor and some memory for the buffers). Closing and re-opening iiod fixes the issue. Also, the local_close() function should not exit on the first fail in finds. It should continue with disabling everything it can. The only error that might make sense, is if the main FD is not initialized. This change simplifies the local_close() a bit: we return -EBADF if the main FD is -1. Other than that, we continue disabling/cleaning everything else (with the proper NULL/fd checks in place). This makes it re-usable for the local_open() exit-on-failure path. This could be addressed [also] by balancing the initialization in the reverse order of init. But it looks like something might be omitted later (as they were up until now) in the exit-on-failure path. So maybe a more future-proof method is to just re-use the local_open() routine where possible. Signed-off-by: Alexandru Ardelean <[email protected]>
- Loading branch information