]> git.llucax.com Git - software/dgc/cdgc.git/commitdiff
Don't segfault if stats files can't be created
authorLeandro Lucarella <llucax@gmail.com>
Thu, 9 Sep 2010 23:05:55 +0000 (20:05 -0300)
committerLeandro Lucarella <llucax@gmail.com>
Thu, 9 Sep 2010 23:05:55 +0000 (20:05 -0300)
If any stats files (used by collect_stats_file and malloc_stats_file)
can't be created, the program segfauls trying to use a null FILE*.

It's extremely impolite to cause an strange segfault because of this, and
since there is no sensible error reporting mechanism either, we just
ignore those options if the selected files are not writable, as we do
with unknown options or any other wrong option parameters.

rt/gc/cdgc/stats.d

index 1a2e8ef18fd2e43db5c4ff938cc1d45c7618f78a..b854812eab740a31cfe5cd1a498dd883a6b9aba2 100644 (file)
@@ -228,8 +228,8 @@ private:
     cstdio.FILE* start_file(char* filename, char* header)
     {
         cstdio.FILE* file = cstdio.fopen(filename, "w");
     cstdio.FILE* start_file(char* filename, char* header)
     {
         cstdio.FILE* file = cstdio.fopen(filename, "w");
-        assert (file !is null);
-        cstdio.fputs(header, file);
+        if (file !is null)
+            cstdio.fputs(header, file);
         return file;
     }
 
         return file;
     }
 
@@ -298,22 +298,24 @@ public:
         Stats this_;
         this_.gc = gc;
         if (options.malloc_stats_file[0] != '\0') {
         Stats this_;
         this_.gc = gc;
         if (options.malloc_stats_file[0] != '\0') {
-            this_.active = true;
             this_.mallocs_file = this_.start_file(
                     options.malloc_stats_file.ptr,
                     "Timestamp,Time,Pointer,Size,Collection triggered,"
                     "Finalize,No scan,No move,Pointer map,Type size,"
                     "Pointer map scan bitmask (first word, hexa),"
                     "Pointer map pointer bitmask (first word, hexa)\n");
             this_.mallocs_file = this_.start_file(
                     options.malloc_stats_file.ptr,
                     "Timestamp,Time,Pointer,Size,Collection triggered,"
                     "Finalize,No scan,No move,Pointer map,Type size,"
                     "Pointer map scan bitmask (first word, hexa),"
                     "Pointer map pointer bitmask (first word, hexa)\n");
+            if (this_.mallocs_file !is null)
+                this_.active = true;
         }
         // collection
         if (options.collect_stats_file[0] != '\0') {
         }
         // collection
         if (options.collect_stats_file[0] != '\0') {
-            this_.active = true;
             this_.collections_file = this_.start_file(
                     options.collect_stats_file.ptr,
                     "Timestamp,Malloc time,Collection time,Stop-the-world time,"
                     "Used before,Free before,Wasted before,Overhead before,"
                     "Used after,Free after,Wasted after,Overhead after\n");
             this_.collections_file = this_.start_file(
                     options.collect_stats_file.ptr,
                     "Timestamp,Malloc time,Collection time,Stop-the-world time,"
                     "Used before,Free before,Wasted before,Overhead before,"
                     "Used after,Free after,Wasted after,Overhead after\n");
+            if (this_.collections_file !is null)
+                this_.active = true;
         }
         this_.program_start = this_.now();
         return this_;
         }
         this_.program_start = this_.now();
         return this_;