From 4c67bd0b35c43be2ead805ac9e69731a356c5ca8 Mon Sep 17 00:00:00 2001 From: Cary R Date: Mon, 3 Nov 2008 11:16:16 -0800 Subject: [PATCH] Fix memory leak and free temp. file names to make valgrind happy. There was a memory leak in the preprocess_only code (cmd was not being freed when the command completed successfully. Valgrind was also marking the temporary file names as still reachable, so they are not memory leaks, but freeing them makes valgrind happier. --- driver/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/driver/main.c b/driver/main.c index fbd8de4df..8d26cf1b2 100644 --- a/driver/main.c +++ b/driver/main.c @@ -263,6 +263,7 @@ static const char*my_tempfile(const char*str, FILE**fout) static int t_version_only(void) { remove(source_path); + free(source_path); fflush(0); snprintf(tmp, sizeof tmp, "%s%civlpp -V", pbase, sep); @@ -275,8 +276,11 @@ static int t_version_only(void) if ( ! getenv("IVERILOG_ICONFIG")) { remove(iconfig_path); + free(iconfig_path); remove(defines_path); + free(defines_path); remove(compiled_defines_path); + free(compiled_defines_path); } return 0; @@ -314,11 +318,15 @@ static int t_preprocess_only(void) rc = system(cmd); remove(source_path); + free(source_path); if ( ! getenv("IVERILOG_ICONFIG")) { remove(iconfig_path); + free(iconfig_path); remove(defines_path); + free(defines_path); remove(compiled_defines_path); + free(compiled_defines_path); } if (rc != 0) { @@ -332,6 +340,7 @@ static int t_preprocess_only(void) return -1; } + free(cmd); return 0; } @@ -410,9 +419,13 @@ static int t_compile() rc = system(cmd); if ( ! getenv("IVERILOG_ICONFIG")) { remove(source_path); + free(source_path); remove(iconfig_path); + free(iconfig_path); remove(defines_path); + free(defines_path); remove(compiled_defines_path); + free(compiled_defines_path); } #ifdef __MINGW32__ /* MinGW just returns the exit status, so return it! */ free(cmd);