Correct memory management around os-release/version
authorTim Pepper <timothy.c.pepper@linux.intel.com>
Thu, 6 Sep 2012 21:56:30 +0000 (14:56 -0700)
committerTim Pepper <timothy.c.pepper@linux.intel.com>
Thu, 6 Sep 2012 21:56:30 +0000 (14:56 -0700)
Valgrind reminded me I should correctly dup the substring and free the
original full string.

Signed-off-by: Tim Pepper <timothy.c.pepper@linux.intel.com>
src/coredump.c

index 2fee61f..ae9fd75 100644 (file)
@@ -79,10 +79,13 @@ static char *get_release(void)
                        char *c = NULL;
 
                        c = strchr(line, '\n');
-                       if (c) *c = 0;
-
-                       fclose(file);
-                       return &line[11];
+                       if (c) {
+                               *c = 0;
+                               c = strdup(&line[11]);
+                               fclose(file);
+                               free(line);
+                               return c;
+                       }
                }
        }