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.
This commit is contained in:
Cary R 2008-11-03 11:16:16 -08:00 committed by Stephen Williams
parent 4f7457fcec
commit 4c67bd0b35
1 changed files with 13 additions and 0 deletions

View File

@ -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);