init: fix more cases of leaking pid_file
[fio.git] / init.c
diff --git a/init.c b/init.c
index e9e49ebb3e478f6db4733714a1663ca567969843..6324dceefeda87959b7b218328bf5111e72f72f9 100644 (file)
--- a/init.c
+++ b/init.c
@@ -364,7 +364,7 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent,
 
        td->thread_number = thread_number;
 
-       if (!parent || !parent->o.group_reporting)
+       if (!parent->o.group_reporting)
                stat_number++;
 
        set_cmd_options(td);
@@ -1719,6 +1719,9 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        write_bw_log = 1;
                        break;
                case 'o':
+                       if (f_out)
+                               fclose(f_out);
+
                        f_out = fopen(optarg, "w+");
                        if (!f_out) {
                                perror("fopen output");
@@ -1828,6 +1831,8 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        break;
                        }
                case 'p':
+                       if (exec_profile)
+                               free(exec_profile);
                        exec_profile = strdup(optarg);
                        break;
                case FIO_GETOPT_JOB: {
@@ -1837,7 +1842,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        if (!strncmp(opt, "name", 4) && td) {
                                ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type);
                                if (ret)
-                                       return 0;
+                                       goto out_free;
                                td = NULL;
                        }
                        if (!td) {
@@ -1852,7 +1857,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
 
                                td = get_new_job(global, &def_thread, 1);
                                if (!td || ioengine_load(td))
-                                       return 0;
+                                       goto out_free;
                                fio_options_set_ioengine_opts(l_opts, td);
                        }
 
@@ -1874,7 +1879,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        if (!ret && !strcmp(opt, "ioengine")) {
                                free_ioengine(td);
                                if (ioengine_load(td))
-                                       return 0;
+                                       goto out_free;
                                fio_options_set_ioengine_opts(l_opts, td);
                        }
                        break;
@@ -1985,6 +1990,8 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
 
        if (is_backend && backend)
                return fio_start_server(pid_file);
+       else if (pid_file)
+               free(pid_file);
 
        if (td) {
                if (!ret)
@@ -1998,6 +2005,10 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                optind++;
        }
 
+out_free:
+       if (pid_file)
+               free(pid_file);
+
        return ini_idx;
 }