rts: Fix potential memory leak in ProfHeap.c
authorAustin Seipp <austin@well-typed.com>
Wed, 23 Apr 2014 07:14:15 +0000 (02:14 -0500)
committerAustin Seipp <austin@well-typed.com>
Sun, 27 Apr 2014 09:18:20 +0000 (04:18 -0500)
Discovered by Coverity. CID 43166.

Signed-off-by: Austin Seipp <austin@well-typed.com>
rts/ProfHeap.c

index d21b14a..9079c2b 100644 (file)
@@ -331,16 +331,17 @@ void initProfiling2 (void)
     /* Initialise the log file name */
     hp_filename = stgMallocBytes(strlen(prog) + 6, "hpFileName");
     sprintf(hp_filename, "%s.hp", prog);
-    
+
     /* open the log file */
     if ((hp_file = fopen(hp_filename, "w")) == NULL) {
-      debugBelch("Can't open profiling report file %s\n", 
+      debugBelch("Can't open profiling report file %s\n",
              hp_filename);
       RtsFlags.ProfFlags.doHeapProfile = 0;
+      stgFree(prog);
       return;
     }
   }
-  
+
   stgFree(prog);
 
   initHeapProfiling();