fix: fix memory leak and potential crash in iq_id_handler_add
`userdata` was not freed if a handler could not be registered. This occurs when the 'id' parameter is NULL. In such cases, the handler cannot be stored in the 'id_handlers' table, but ownership of 'userdata' has already been transferred to this function. This commit ensures 'free_func' is called if 'id' is NULL since we always need to have an ID.
This commit is contained in:
@@ -364,14 +364,19 @@ _iq_id_handler_free(ProfIqHandler* handler)
|
||||
void
|
||||
iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata)
|
||||
{
|
||||
ProfIqHandler* handler = g_new0(ProfIqHandler, 1);
|
||||
if (handler) {
|
||||
handler->func = func;
|
||||
handler->free_func = free_func;
|
||||
handler->userdata = userdata;
|
||||
|
||||
g_hash_table_insert(id_handlers, strdup(id), handler);
|
||||
if (id == NULL) {
|
||||
if (free_func) {
|
||||
free_func(userdata);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
ProfIqHandler* handler = g_new0(ProfIqHandler, 1);
|
||||
handler->func = func;
|
||||
handler->free_func = free_func;
|
||||
handler->userdata = userdata;
|
||||
|
||||
g_hash_table_insert(id_handlers, strdup(id), handler);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user