Skip to content

An improper locking due to the unreleased lock before program exit #6

Description

@ycaibb

Hi developers, in the below codes, the lock daemon could be not released before program's exit abort();. I think it is better to write MHD_ip_count_unlock (daemon); before the abort(); for better resource management and code symmetry. Thanks!

MHD_ip_count_lock (daemon);
/* Search for the IP address */
node = (void*)TFIND (&search_key, &daemon->per_ip_connection_count, MHD_ip_addr_compare);
/* Something's wrong if we couldn't find an IP address
* that was previously added */
if (!node)
{
#if HAVE_MESSAGES
MHD_DLOG (daemon,
"Failed to find previously-added IP address\n");
#endif
abort();
}
found_key = (struct MHD_IPCount*)*(void**)node;
/* Validate existing count for IP address */
if (found_key->count == 0)
{
#if HAVE_MESSAGES
MHD_DLOG (daemon,
"Previously-added IP address had 0 count\n");
#endif
abort();
}
/* Remove the node entirely if count reduces to 0 */
if (--found_key->count == 0)
{
TDELETE (found_key, &daemon->per_ip_connection_count, MHD_ip_addr_compare);
free (found_key);
}
MHD_ip_count_unlock (daemon);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions