Skip to content

Commit

Permalink
Add missing mutex acquisition when manipulating active_contexts_list
Browse files Browse the repository at this point in the history
The `active_contexts_list` is supposed to be protected by the
`active_contexts_lock` mutex.

Upon code review, found one place where the mutex was not acquired.
  • Loading branch information
seanm authored and tormodvolden committed Jan 9, 2024
1 parent a0f0355 commit cb7a78c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libusb/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2438,10 +2438,12 @@ int API_EXPORTED libusb_init_context(libusb_context **ctx, const struct libusb_i
}

/* check for first init */
usbi_mutex_static_lock(&active_contexts_lock);
if (!active_contexts_list.next) {
list_init(&active_contexts_list);
usbi_get_monotonic_time(&timestamp_origin);
}
usbi_mutex_static_unlock(&active_contexts_lock);

_ctx = calloc(1, PTR_ALIGN(sizeof(*_ctx)) + priv_size);
if (!_ctx) {
Expand Down

0 comments on commit cb7a78c

Please sign in to comment.