tools: Fix string leak

Only allocate the return string when we know we are going to return
it.

Coverity CID #1292292
This commit is contained in:
Edward Hervey 2015-04-22 15:07:58 +02:00 committed by Edward Hervey
parent 1aeb6e691e
commit e651c43914

View file

@ -29,8 +29,7 @@ _sanitize_argument (gchar * arg)
{
char *equal_index = strstr (arg, "=");
char *space_index = strstr (arg, " ");
gchar *new_string = g_malloc (sizeof (gchar) * (strlen (arg) + 3));
gchar *tmp_string = new_string;
gchar *new_string, *tmp_string;
if (!space_index)
return g_strdup (arg);
@ -38,6 +37,8 @@ _sanitize_argument (gchar * arg)
if (!equal_index || equal_index > space_index)
return g_strdup_printf ("\"%s\"", arg);
tmp_string = new_string = g_malloc (sizeof (gchar) * (strlen (arg) + 3));
for (; *arg != '\0'; arg++) {
*tmp_string = *arg;
tmp_string += 1;