summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-06-26 00:26:16 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-06-26 00:26:16 +0000
commitfa95cc916fe29b5746ccab7743eabd984ac9e0ef (patch)
treeaddfba4e7e0922b4b0dc775eb812dc62bd195209
parent8084cffd0ba9553dfaa335c58dcba7b55dbff84a (diff)
downloadbcm5719-llvm-fa95cc916fe29b5746ccab7743eabd984ac9e0ef.tar.gz
bcm5719-llvm-fa95cc916fe29b5746ccab7743eabd984ac9e0ef.zip
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! llvm-svn: 184895
-rw-r--r--compiler-rt/lib/profile/GCDAProfiling.c27
1 files changed, 13 insertions, 14 deletions
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
index 33803976a38..4420dbb488c 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/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");
OpenPOWER on IntegriCloud