diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-06-26 00:26:16 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-06-26 00:26:16 +0000 |
commit | cf5fb62c0206c6544c464fa1b414bbfa26cb3244 (patch) | |
tree | 31db872911630b224ba7589b8f3aeb51d0a6eb74 /lib/profile | |
parent | 7caabbd43ef867fa93317bef61924197b97ea1c7 (diff) | |
download | compiler-rt-cf5fb62c0206c6544c464fa1b414bbfa26cb3244.tar.gz |
Fix a use after free I introduced and that Bill caught in code review
(thanks!) by deferring the free of the filename until we finish writing
the coverage data to that file.
Bill, let me know if you'd prefer a different approach!
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@184895 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/profile')
-rw-r--r-- | lib/profile/GCDAProfiling.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/profile/GCDAProfiling.c b/lib/profile/GCDAProfiling.c index 33803976a..4420dbb48 100644 --- a/lib/profile/GCDAProfiling.c +++ b/lib/profile/GCDAProfiling.c @@ -271,7 +271,6 @@ void llvm_gcda_start_file(const char *orig_filename, const char version[4]) { fprintf(stderr, "profiling: %s: cannot open: %s\n", filename, strerror(errnum)); #endif - free(filename); return; } } @@ -303,8 +302,6 @@ void llvm_gcda_start_file(const char *orig_filename, const char version[4]) { write_bytes(version, 4); write_bytes("MVLL", 4); - free(filename); - #ifdef DEBUG_GCDAPROFILING fprintf(stderr, "llvmgcda: [%s]\n", orig_filename); #endif @@ -409,19 +406,21 @@ void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) { void llvm_gcda_end_file() { /* Write out EOF record. */ - if (!output_file) return; - write_bytes("\0\0\0\0\0\0\0\0", 8); + if (output_file) { + write_bytes("\0\0\0\0\0\0\0\0", 8); + + if (new_file) { + fwrite(write_buffer, cur_pos, 1, output_file); + free(write_buffer); + } else { + unmap_file(); + } - if (new_file) { - fwrite(write_buffer, cur_pos, 1, output_file); - free(write_buffer); - } else { - unmap_file(); + fclose(output_file); + output_file = NULL; + write_buffer = NULL; } - - fclose(output_file); - output_file = NULL; - write_buffer = NULL; + free(filename); #ifdef DEBUG_GCDAPROFILING fprintf(stderr, "llvmgcda: -----\n"); |