mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-19 08:42:09 +01:00
xdgmimeglob: Fix a memory leak on a duplicate-entry path
Rather than `strdup()`ing strings when passing them into `_xdg_glob_list_append()`, `strdup()` them *inside* the function instead. This avoids a leak in the case that the list entry (tuple of `data` and `mime_type`) already exists in the list. This has been upstreamed as https://gitlab.freedesktop.org/xdg/xdgmime/-/merge_requests/36. Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
parent
747e3af998
commit
21f5e175d4
@ -98,7 +98,7 @@ _xdg_glob_list_free (XdgGlobList *glob_list)
|
|||||||
|
|
||||||
static XdgGlobList *
|
static XdgGlobList *
|
||||||
_xdg_glob_list_append (XdgGlobList *glob_list,
|
_xdg_glob_list_append (XdgGlobList *glob_list,
|
||||||
void *data,
|
const char *data,
|
||||||
const char *mime_type,
|
const char *mime_type,
|
||||||
int weight,
|
int weight,
|
||||||
int case_sensitive)
|
int case_sensitive)
|
||||||
@ -117,8 +117,8 @@ _xdg_glob_list_append (XdgGlobList *glob_list,
|
|||||||
}
|
}
|
||||||
|
|
||||||
new_element = _xdg_glob_list_new ();
|
new_element = _xdg_glob_list_new ();
|
||||||
new_element->data = data;
|
new_element->data = strdup (data);
|
||||||
new_element->mime_type = mime_type;
|
new_element->mime_type = strdup (mime_type);
|
||||||
new_element->weight = weight;
|
new_element->weight = weight;
|
||||||
new_element->case_sensitive = case_sensitive;
|
new_element->case_sensitive = case_sensitive;
|
||||||
if (glob_list == NULL)
|
if (glob_list == NULL)
|
||||||
@ -576,13 +576,13 @@ _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash,
|
|||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case XDG_GLOB_LITERAL:
|
case XDG_GLOB_LITERAL:
|
||||||
glob_hash->literal_list = _xdg_glob_list_append (glob_hash->literal_list, strdup (glob), strdup (mime_type), weight, case_sensitive);
|
glob_hash->literal_list = _xdg_glob_list_append (glob_hash->literal_list, glob, mime_type, weight, case_sensitive);
|
||||||
break;
|
break;
|
||||||
case XDG_GLOB_SIMPLE:
|
case XDG_GLOB_SIMPLE:
|
||||||
glob_hash->simple_node = _xdg_glob_hash_insert_text (glob_hash->simple_node, glob + 1, mime_type, weight, case_sensitive);
|
glob_hash->simple_node = _xdg_glob_hash_insert_text (glob_hash->simple_node, glob + 1, mime_type, weight, case_sensitive);
|
||||||
break;
|
break;
|
||||||
case XDG_GLOB_FULL:
|
case XDG_GLOB_FULL:
|
||||||
glob_hash->full_list = _xdg_glob_list_append (glob_hash->full_list, strdup (glob), strdup (mime_type), weight, case_sensitive);
|
glob_hash->full_list = _xdg_glob_list_append (glob_hash->full_list, glob, mime_type, weight, case_sensitive);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user