Fix potential NULL dereference in alloc_mem_mmap()
[fio.git] / init.c
diff --git a/init.c b/init.c
index 7e456b20d3466d8c9b9e83858623833fa1d6ae6d..fcc135e65eaf1f2f721f310aa8d6355c1331967d 100644 (file)
--- a/init.c
+++ b/init.c
@@ -942,7 +942,7 @@ static char *make_filename(char *buf, struct thread_options *o,
 {
        struct fpre_keyword *f;
        char copy[PATH_MAX];
-       size_t dst_left = PATH_MAX;
+       size_t dst_left = PATH_MAX - 1;
 
        if (!o->filename_format || !strlen(o->filename_format)) {
                sprintf(buf, "%s.%d.%d", jobname, jobnum, filenum);
@@ -1458,9 +1458,6 @@ int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type)
                i++;
        }
 
-       for (i = 0; i < num_opts; i++)
-               free(opts[i]);
-
        free(string);
        free(name);
        free(opts);
@@ -1910,6 +1907,10 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                case FIO_GETOPT_IOENGINE: {
                        const char *opt = l_opts[lidx].name;
                        char *val = optarg;
+
+                       if (!td)
+                               break;
+
                        ret = fio_cmd_ioengine_option_parse(td, opt, val);
                        break;
                }
@@ -1937,6 +1938,8 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        backend = 1;
                        break;
                case 'D':
+                       if (optarg)
+                               free(optarg);
                        pid_file = strdup(optarg);
                        break;
                case 'I':