deploy: Fix leaks in parsing /etc/os-release

This one is a bit subtle; we're generating a hash that contains
pointers to the strings we parsed, so we need to carefully track
ownership.

Closes: #410
Approved by: giuseppe
This commit is contained in:
Colin Walters 2016-07-24 15:40:49 -04:00 committed by Atomic Bot
parent 707ef93097
commit 27559c58a9

View File

@ -1244,13 +1244,13 @@ static GHashTable *
parse_os_release (const char *contents, parse_os_release (const char *contents,
const char *split) const char *split)
{ {
char **lines = g_strsplit (contents, split, -1); g_autofree char **lines = g_strsplit (contents, split, -1);
char **iter; char **iter;
GHashTable *ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); GHashTable *ret = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
for (iter = lines; *iter; iter++) for (iter = lines; *iter; iter++)
{ {
char *line = *iter; g_autofree char *line = *iter;
char *eq; char *eq;
const char *quotedval; const char *quotedval;
char *val; char *val;
@ -1268,7 +1268,7 @@ parse_os_release (const char *contents,
if (!val) if (!val)
continue; continue;
g_hash_table_insert (ret, line, val); g_hash_table_insert (ret, g_steal_pointer (&line), val);
} }
return ret; return ret;