[Libosinfo] [PATCH 02/14] entity: Fix osinfo_entity_get_param_keys() leak
Christophe Fergeau
cfergeau at redhat.com
Wed Jun 8 10:01:06 UTC 2016
The content of the GList returned by osinfo_entity_get_param_key() is
not owned by the caller, but by OsinfoEntity. However, the "id" field
added to the list was owned by the caller, and could not be freed
properly. This commit adds a const char * to the GList rather than
adding a g_strdup'ed string in order to fix this leak.
==12129== 3 bytes in 1 blocks are definitely lost in loss record 7 of 269
==12129== at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
==12129== by 0x684FE58: g_malloc (gmem.c:94)
==12129== by 0x686889E: g_strdup (gstrfuncs.c:363)
==12129== by 0x532BB81: osinfo_entity_get_param_keys (osinfo_entity.c:300)
==12129== by 0x401AFF: test_multi_props_clear (test-entity.c:266)
==12129== by 0x5117535: tcase_run_tfun_nofork.isra.9 (check_run.c:390)
==12129== by 0x51178EB: srunner_iterate_tcase_tfuns (check_run.c:231)
==12129== by 0x51178EB: srunner_run_tcase (check_run.c:373)
==12129== by 0x51178EB: srunner_iterate_suites (check_run.c:195)
==12129== by 0x51178EB: srunner_run (check_run.c:782)
==12129== by 0x401369: main (test-entity.c:344)
---
osinfo/osinfo_entity.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/osinfo/osinfo_entity.c b/osinfo/osinfo_entity.c
index 7e27930..20b9115 100644
--- a/osinfo/osinfo_entity.c
+++ b/osinfo/osinfo_entity.c
@@ -297,7 +297,7 @@ GList *osinfo_entity_get_param_keys(OsinfoEntity *entity)
{
g_return_val_if_fail(OSINFO_IS_ENTITY(entity), NULL);
GList *keys = g_hash_table_get_keys(entity->priv->params);
- keys = g_list_append(keys, g_strdup("id"));
+ keys = g_list_append(keys, (char *)"id");
return keys;
}
--
2.7.4
More information about the Libosinfo
mailing list