LibtraceTeam / libtrace

C Library for working with network packet traces
GNU Lesser General Public License v3.0
155 stars 50 forks source link

Double unlocking of the lock b->lock #197

Closed ycaibb closed 3 years ago

ycaibb commented 3 years ago

Dear developers, there is a double unlocking bug in the below code, thank you for your checking.

        while (b->packets[b->nextid] != NULL) {
                /* No more packet slots available! */
                pthread_cond_wait(&b->cond, &b->lock);
                pthread_mutex_unlock(&b->lock); // the first time

        }
        b->packets[b->nextid] = b->node;
        b->node->activemembers ++;
        b->node->released[s] = 1;
        b->nextid ++;
        ret = b->nextid - 1;
        pthread_mutex_unlock(&b->lock);  // the second time

https://github.com/ycaibb/libtrace/blob/master/lib/data-struct/buckets.c#L161-L172

ycaibb commented 3 years ago

Similarly, https://github.com/LibtraceTeam/libtrace/blob/d827850a048405324dcdb39feeee8b3dd01378a6/lib/data-struct/buckets.c#L127-L142

salcock commented 3 years ago

Should now be fixed in the develop branch, thank you for bringing this to our attention.