From: Jens Axboe Date: Thu, 7 May 2015 20:23:38 +0000 (-0600) Subject: Fix keyword replacement leaks X-Git-Tag: fio-2.2.8~5 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=af1dc26601999b071522562dee7ba6db6bae29ee Fix keyword replacement leaks Signed-off-by: Jens Axboe --- diff --git a/fio.c b/fio.c index 9adc29ae..ee6eae24 100644 --- 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 0d5a0efb..6659e280 100644 --- 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 diff --git a/libfio.c b/libfio.c index ed26114d..3a28f55e 100644 --- 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(); +} diff --git a/options.c b/options.c index cb8182de..f21ed260 100644 --- 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;