glib-compile-resources: do not leak c_name

As per #578363, "if one requests e.g. strings via GOptionEntry.arg_data
then those are strduped and needs to be free'ed by the application."

Fixes following leak:

=================================================================
==29426==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 10 byte(s) in 1 object(s) allocated from:
    0 0x7f3ab783d37a in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9437a)
    1 0x7f3ab70f7c82 in g_malloc /home/lebedevri/src/glib/glib/gmem.c:94
    2 0x7f3ab70f7f60 in g_malloc_n /home/lebedevri/src/glib/glib/gmem.c:330
    3 0x7f3ab713258e in g_strndup /home/lebedevri/src/glib/glib/gstrfuncs.c:425
    4 0x7f3ab709c86b in strdup_len /home/lebedevri/src/glib/glib/gconvert.c:864
    5 0x7f3ab709c966 in g_locale_to_utf8 /home/lebedevri/src/glib/glib/gconvert.c:905
    6 0x7f3ab7103c32 in parse_arg /home/lebedevri/src/glib/glib/goption.c:1276
    7 0x7f3ab71066fb in parse_long_option /home/lebedevri/src/glib/glib/goption.c:1670
    8 0x7f3ab7108047 in g_option_context_parse /home/lebedevri/src/glib/glib/goption.c:1997
    9 0x408532 in main /home/lebedevri/src/glib/gio/glib-compile-resources.c:629
    10 0x7f3ab6c72b44 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b44)

https://bugzilla.gnome.org/show_bug.cgi?id=757299
This commit is contained in:
Roman Lebedev 2015-10-29 14:41:48 +03:00 committed by Matthias Clasen
parent 3272267b99
commit 4cda92b587

View File

@ -637,6 +637,7 @@ main (int argc, char **argv)
if (argc != 2)
{
g_printerr (_("You should give exactly one file name\n"));
g_free (c_name);
return 1;
}
@ -701,6 +702,7 @@ main (int argc, char **argv)
if ((table = parse_resource_file (srcfile, !generate_dependencies)) == NULL)
{
g_free (target);
g_free (c_name);
return 1;
}
@ -725,6 +727,7 @@ main (int argc, char **argv)
if (fd == -1)
{
g_printerr ("Can't open temp file\n");
g_free (c_name);
return 1;
}
close (fd);
@ -770,6 +773,7 @@ main (int argc, char **argv)
{
g_printerr ("%s\n", error->message);
g_free (target);
g_free (c_name);
return 1;
}
@ -781,6 +785,7 @@ main (int argc, char **argv)
if (file == NULL)
{
g_printerr ("can't write to file %s", target);
g_free (c_name);
return 1;
}
@ -817,6 +822,7 @@ main (int argc, char **argv)
&data_size, NULL))
{
g_printerr ("can't read back temporary file");
g_free (c_name);
return 1;
}
g_unlink (binary_target);
@ -825,6 +831,7 @@ main (int argc, char **argv)
if (file == NULL)
{
g_printerr ("can't write to file %s", target);
g_free (c_name);
return 1;
}
@ -920,6 +927,7 @@ main (int argc, char **argv)
g_free (target);
g_hash_table_destroy (table);
g_free (xmllint);
g_free (c_name);
return 0;
}