An improper locking bug on the lock iv_wait_lock
Closed this issue · 2 comments
Hi developers, in the below codes, the lock iv_wait_lock
could be not released before program's exit. I think it is better to write unlock ___mutex_unlock(&iv_wait_lock);
before the exit exit(1);
for better resource management and code symmetry.
Lines 291 to 309 in f1b1455
Hello! Thank you for your comment.
In the if (pid == 0) {
block, we are in the child process that is created by fork()
, and the child process will have a copy-on-write copy of all of the parent's memory areas, including of iv_wait_lock
, and freeing that lock here will actually do nothing -- in particular, it will not free the lock in the parent process.
Also, the fn(cookie);
call typically does not return -- see for example how src/iv_popen.c
or test.mt/iv_wait_test.c
use iv_wait_interest_register_spawn()
-- and the exit(1);
call is here only as a safeguard in case the fn(cookie);
call accidentally does return.
In other words, the fact that the child process does not explicitly free iv_wait_lock
is intended. :)