diff options
author | Pablo Barciela <[email protected]> | 2019-03-21 12:41:47 +0100 |
---|---|---|
committer | Pablo Barciela <[email protected]> | 2019-03-31 00:15:08 +0100 |
commit | 44d2b1e74cf31b2b80fcdae4c02356cea31bf154 (patch) | |
tree | 59b0ae450ad0921d5841b7558fb0510ead3181bf /src/fr-process.c | |
parent | 79bae43e3f35fcaeca32ba1d3df088b9d0038434 (diff) | |
download | engrampa-44d2b1e74cf31b2b80fcdae4c02356cea31bf154.tar.bz2 engrampa-44d2b1e74cf31b2b80fcdae4c02356cea31bf154.tar.xz |
fr-process: Fix memory leak: 'g_strconcat' needs to be freed
Use 'GString' instead 'g_strconcat'
Diffstat (limited to 'src/fr-process.c')
-rw-r--r-- | src/fr-process.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/fr-process.c b/src/fr-process.c index 9404089..cc8887e 100644 --- a/src/fr-process.c +++ b/src/fr-process.c @@ -676,7 +676,7 @@ start_current_command (FrProcess *process) char **argv; int out_fd, err_fd; int i = 0; - char *commandline = ""; + GString *commandline = g_string_new (""); gboolean fixname = FALSE; debug (DEBUG_INFO, "%d/%d) ", process->priv->current_command, process->priv->n_comm); @@ -688,9 +688,9 @@ start_current_command (FrProcess *process) for (scan = info->args; scan; scan = scan->next) { argv[i++] = scan->data; - if (g_str_has_prefix (commandline, "mv")) { + if (g_str_has_prefix (commandline->str, "mv")) { - if ((i==3) && (!g_file_test (argv[2], G_FILE_TEST_EXISTS)) && (!fixname)) { + if ((i == 3) && (!g_file_test (argv[2], G_FILE_TEST_EXISTS)) && (!fixname)) { char rarfile[strlen (argv[2]) + 7]; g_strlcpy (rarfile, argv[2], sizeof (rarfile)); @@ -698,22 +698,31 @@ start_current_command (FrProcess *process) g_strlcat (rarfile, "part1.rar", sizeof (rarfile)); if (g_str_has_suffix (argv[2], ".7z")) { - commandline = g_strconcat (commandline, " ", g_shell_quote (argv[2]), ".*", NULL); + g_string_append (commandline, " "); + g_string_append (commandline, g_shell_quote (argv[2])); + g_string_append (commandline, ".*"); fixname = TRUE; } else if (g_str_has_suffix (argv[2], ".rar")) { rarfile[strlen(rarfile) - 5] = 0; - commandline = g_strconcat (commandline, " ", g_shell_quote (rarfile), "*.rar", NULL); + g_string_append (commandline, " "); + g_string_append (commandline, g_shell_quote (rarfile)); + g_string_append (commandline, "*.rar"); fixname = TRUE; } } - else if ((i==4) && (fixname)) - commandline = g_strconcat (commandline, " \"$(dirname ", g_shell_quote (argv[3]), ")\"", NULL); - else - commandline = g_strconcat (commandline, " ", argv[(i - 1)], NULL); + else if ((i == 4) && (fixname)) { + g_string_append (commandline, " \"$(dirname "); + g_string_append (commandline, g_shell_quote (argv[3])); + g_string_append (commandline, ")\""); + } + else { + g_string_append (commandline, " "); + g_string_append (commandline, argv[(i - 1)]); + } } else if (g_str_has_prefix (argv[0], "mv")) { - commandline = g_strconcat (commandline, "mv", NULL); + g_string_append (commandline, "mv"); } } @@ -736,8 +745,8 @@ start_current_command (FrProcess *process) } #endif - if ((fixname) && (system (commandline) != 0)) - g_warning ("The files could not be move: %s\n", commandline); + if ((fixname) && (system (commandline->str) != 0)) + g_warning ("The files could not be move: %s\n", commandline->str); if (info->begin_func != NULL) (*info->begin_func) (info->begin_data); @@ -761,10 +770,12 @@ start_current_command (FrProcess *process) fr_process_signals[DONE], 0, &process->error); + g_string_free (commandline, TRUE); g_free (argv); return; } + g_string_free (commandline, TRUE); g_free (argv); fr_channel_data_set_fd (&process->out, out_fd, fr_process_get_charset (process)); |