Fix keyword replacement leaks
authorJens Axboe <axboe@fb.com>
Thu, 7 May 2015 20:23:38 +0000 (14:23 -0600)
committerJens Axboe <axboe@fb.com>
Thu, 7 May 2015 20:23:38 +0000 (14:23 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
fio.c
fio.h
libfio.c
options.c

diff --git a/fio.c b/fio.c
index 9adc29aee47bbbfe9198a67458fc17c5d8b456b1..ee6eae24c91acd14fc72884b700fd801fb31246e 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -30,6 +30,8 @@
 
 int main(int argc, char *argv[], char *envp[])
 {
+       int ret = 1;
+
        if (initialize_fio(envp))
                return 1;
 
@@ -38,7 +40,7 @@ int main(int argc, char *argv[], char *envp[])
 #endif
 
        if (parse_options(argc, argv))
-               return 1;
+               goto done;
 
        fio_time_init();
 
@@ -46,8 +48,12 @@ int main(int argc, char *argv[], char *envp[])
                set_genesis_time();
 
                if (fio_start_all_clients())
-                       return 1;
-               return fio_handle_clients(&fio_client_ops);
+                       goto done;
+               ret = fio_handle_clients(&fio_client_ops);
        } else
-               return fio_backend();
+               ret = fio_backend();
+
+done:
+       deinitialize_fio();
+       return ret;
 }
diff --git a/fio.h b/fio.h
index 0d5a0efb5882cbcef8fd11739667686ea6363a8c..6659e2800cc3c000433e3cfc4ddbb81c418badd9 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -464,6 +464,7 @@ extern void reset_fio_state(void);
 extern void clear_io_state(struct thread_data *);
 extern int fio_options_parse(struct thread_data *, char **, int, int);
 extern void fio_keywords_init(void);
+extern void fio_keywords_exit(void);
 extern int fio_cmd_option_parse(struct thread_data *, const char *, char *);
 extern int fio_cmd_ioengine_option_parse(struct thread_data *, const char *, char *);
 extern void fio_fill_default_options(struct thread_data *);
@@ -483,6 +484,7 @@ extern int fio_set_fd_nonblocking(int, const char *);
 extern uintptr_t page_mask;
 extern uintptr_t page_size;
 extern int initialize_fio(char *envp[]);
+extern void deinitialize_fio(void);
 
 #define FIO_GETOPT_JOB         0x89000000
 #define FIO_GETOPT_IOENGINE    0x98000000
index ed26114d452fe4488a238ac04a7c4fd6da9e5624..3a28f55e2139d8fac9becf617ee23de0ff0fbab8 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -353,3 +353,8 @@ int initialize_fio(char *envp[])
        fio_keywords_init();
        return 0;
 }
+
+void deinitialize_fio(void)
+{
+       fio_keywords_exit();
+}
index cb8182de93c259a8ef2f3bc9141aa9795b2bbda4..f21ed260d0277ed25286b7dd3e3b98fbca653a17 100644 (file)
--- a/options.c
+++ b/options.c
@@ -3822,6 +3822,18 @@ static struct fio_keyword fio_keywords[] = {
        },
 };
 
+void fio_keywords_exit(void)
+{
+       struct fio_keyword *kw;
+
+       kw = &fio_keywords[0];
+       while (kw->word) {
+               free(kw->replace);
+               kw->replace = NULL;
+               kw++;
+       }
+}
+
 void fio_keywords_init(void)
 {
        unsigned long long mb_memory;