From: Joel Rosdahl Date: Wed, 14 Jul 2010 17:40:35 +0000 (+0200) Subject: Clean up long-lived temporary files with an exit function X-Git-Tag: v3.1~197 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=932a3555aa7b0b89b3087971f6f4b3bf18fc6874;p=thirdparty%2Fccache.git Clean up long-lived temporary files with an exit function --- diff --git a/ccache.c b/ccache.c index 556d6de40..7678ba524 100644 --- a/ccache.c +++ b/ccache.c @@ -253,22 +253,6 @@ static void failed(void) { char *e; - /* delete intermediate pre-processor file if needed */ - if (i_tmpfile) { - if (!direct_i_file) { - unlink(i_tmpfile); - } - free(i_tmpfile); - i_tmpfile = NULL; - } - - /* delete the cpp stderr file if necessary */ - if (cpp_stderr) { - unlink(cpp_stderr); - free(cpp_stderr); - cpp_stderr = NULL; - } - /* strip any local args */ args_strip(orig_args, "--ccache-"); @@ -287,6 +271,26 @@ static void failed(void) fatal("%s: execv returned (%s)", orig_args->argv[0], strerror(errno)); } +static void +clean_up_tmp_files() +{ + /* delete intermediate pre-processor file if needed */ + if (i_tmpfile) { + if (!direct_i_file) { + unlink(i_tmpfile); + } + free(i_tmpfile); + i_tmpfile = NULL; + } + + /* delete the cpp stderr file if necessary */ + if (cpp_stderr) { + unlink(cpp_stderr); + free(cpp_stderr); + cpp_stderr = NULL; + } +} + /* * Transform a name to a full path into the cache directory, creating needed * sublevels if needed. Caller frees. @@ -679,10 +683,7 @@ static void to_cache(ARGS *args) close(fd_real_stderr); close(fd_result); unlink(tmp_stderr2); - unlink(cpp_stderr); free(tmp_stderr2); - free(cpp_stderr); - cpp_stderr = NULL; } if (status != 0) { @@ -701,9 +702,6 @@ static void to_cache(ARGS *args) copy_fd(fd, 2); close(fd); unlink(tmp_stderr); - if (i_tmpfile && !direct_i_file) { - unlink(i_tmpfile); - } exit(status); } } @@ -1221,22 +1219,6 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest } } - /* get rid of the intermediate preprocessor file */ - if (i_tmpfile) { - if (!direct_i_file) { - unlink(i_tmpfile); - } - free(i_tmpfile); - i_tmpfile = NULL; - } - - /* Delete the cpp stderr file if necessary. */ - if (cpp_stderr) { - unlink(cpp_stderr); - free(cpp_stderr); - cpp_stderr = NULL; - } - /* Send the stderr, if any. */ fd_stderr = open(cached_stderr, O_RDONLY | O_BINARY); if (fd_stderr != -1) { @@ -2137,6 +2119,7 @@ int main(int argc, char *argv[]) exitfn_init(); exitfn_add_nullary(stats_flush); + exitfn_add_nullary(clean_up_tmp_files); /* check for logging early so cc_log messages start working ASAP */ cache_logfile = getenv("CCACHE_LOGFILE");