Free/alloc every FIO_OPT_STR_STORE string
authorJens Axboe <jens.axboe@oracle.com>
Fri, 23 Mar 2007 14:57:56 +0000 (15:57 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Fri, 23 Mar 2007 14:57:56 +0000 (15:57 +0100)
Makes ownership clear, though the freeing is a bit anal.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fio.c
fio.h
init.c
options.c

diff --git a/fio.c b/fio.c
index 9fabbe93bc53a7887cc6457371b55ea202ff3ebc..f6c3fc8fe555ca31e78b7eb1666dfa6ac27185f7 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -878,6 +878,7 @@ err:
        close_files(td);
        close_ioengine(td);
        cleanup_io_u(td);
+       options_mem_free(td);
        td_set_runstate(td, TD_EXITED);
        return (void *) (unsigned long) td->error;
 err_sem:
diff --git a/fio.h b/fio.h
index 8a79289cb77fe9c8d14535276b8181ad41686b5a..736fefb1dd0c6256b98f8a73864af6982ee493ac 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -691,6 +691,8 @@ extern int fio_cmd_option_parse(struct thread_data *, const char *, char *);
 extern void fio_fill_default_options(struct thread_data *);
 extern int fio_show_option_help(const char *);
 extern void fio_options_dup_and_init(struct option *);
+extern void options_mem_dupe(struct thread_data *);
+extern void options_mem_free(struct thread_data *);
 #define FIO_GETOPT_JOB         0x89988998
 #define FIO_NR_OPTIONS         128
 
diff --git a/init.c b/init.c
index e5d776c22f6a13481508a565c2d76671d2475faf..c1f774d8e03f42df01dd5c0298a2013d0ba6343b 100644 (file)
--- a/init.c
+++ b/init.c
@@ -116,6 +116,7 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent)
        *td = *parent;
 
        dup_files(td, parent);
+       options_mem_dupe(td);
 
        td->thread_number = thread_number;
        return td;
@@ -801,6 +802,7 @@ int parse_options(int argc, char *argv[])
        }
 
        free(ini_file);
+       options_mem_free(&def_thread);
 
        if (!thread_number) {
                log_err("No jobs defined(s)\n");
index 4f30f2c1991aaf8769e2802d4dceef7cb0d83a34..7d4396e81d1aa637748bd135c52e520c09beb7ca 100644 (file)
--- a/options.c
+++ b/options.c
@@ -864,3 +864,39 @@ int fio_show_option_help(const char *opt)
 {
        return show_cmd_help(options, opt);
 }
+
+static void __options_mem(struct thread_data *td, int alloc)
+{
+       struct thread_options *o = &td->o;
+       struct fio_option *opt;
+       char **ptr;
+       int i;
+
+       for (i = 0, opt = &options[0]; opt->name; i++, opt = &options[i]) {
+               if (opt->type != FIO_OPT_STR_STORE)
+                       continue;
+
+               ptr = (void *) o + opt->off1;
+               if (*ptr) {
+                       if (alloc)
+                               *ptr = strdup(*ptr);
+                       else {
+                               free(*ptr);
+                               *ptr = NULL;
+                       }
+               }
+       }
+}
+
+/*
+ * dupe FIO_OPT_STR_STORE options
+ */
+void options_mem_dupe(struct thread_data *td)
+{
+       __options_mem(td, 1);
+}
+
+void options_mem_free(struct thread_data *td)
+{
+       __options_mem(td, 0);
+}