libguestfs/nbdkit

A potential error due to the unreleased lock

Closed this issue · 6 comments

Dear developers: Thank you for your checking. It seems there is a lock resource leak on the lock paused. I think the lock should be released at the end of do_pause?

static void
do_pause (void)
{
if (is_paused) return;
/* Grabbing the paused lock is enough to stop request processing. */
pthread_mutex_lock (&paused);
is_paused = true;
/* However we must also wait until all outstanding requests have
* been completed before we send the acknowledgement.
*/
nbdkit_debug ("pause: pausing, waiting for requests to complete");
ACQUIRE_LOCK_FOR_CURRENT_SCOPE (&count_lock);
while (count_requests > 0)
pthread_cond_wait (&count_cond, &count_lock);
nbdkit_debug ("pause: paused");
}

Which lock do you mean?

This one

pthread_mutex_lock (&paused);

It is unlocked in the next function.

But here is a break?

case 'p':
do_pause ();
break;
case 'r':
do_resume ();

do_resume (void)
{
if (!is_paused) return;
/* Release the worker threads. */
pthread_mutex_unlock (&paused);
is_paused = false;
nbdkit_debug ("pause: resumed");
}

https://libguestfs.org/nbdkit-pause-filter.1.html#Control-socket
Would suggest reading how the pause filter works. Unless there is a specific problem you are seeing I will close this issue. BTW gitlab is the site used for nbdkit: https://gitlab.com/nbdkit/nbdkit

This case is detected by our static code analyzer, which might be a false positive. Thank you very much for your time.