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
|
void
|
||||||
iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata)
|
iq_id_handler_add(const char* const id, ProfIqCallback func, ProfIqFreeCallback free_func, void* userdata)
|
||||||
{
|
{
|
||||||
ProfIqHandler* handler = g_new0(ProfIqHandler, 1);
|
if (id == NULL) {
|
||||||
if (handler) {
|
if (free_func) {
|
||||||
handler->func = func;
|
free_func(userdata);
|
||||||
handler->free_func = free_func;
|
}
|
||||||
handler->userdata = userdata;
|
return;
|
||||||
|
|
||||||
g_hash_table_insert(id_handlers, strdup(id), handler);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user