Free memory leaks in mnemon_save (thanks valgrind!)
authorCarl Worth <cworth@cworth.org>
Tue, 17 Apr 2007 15:20:45 +0000 (08:20 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 17 Apr 2007 15:20:45 +0000 (08:20 -0700)
mnemon.c

index f35c0b7aabd8696520aef61f03239661b3ec65ba..101ace80edb9f29d49232261de5db331931a847a 100644 (file)
--- a/mnemon.c
+++ b/mnemon.c
@@ -503,6 +503,7 @@ mnemon_save (mnemon_t *mnemon)
                   mnemon->dir_name, category->name);
        xasprintf (&lock_filename, "%s/.#%s",
                   mnemon->dir_name, category->name);
+
        file = fopen (lock_filename, "w");
        if (file == NULL) {
            fprintf (stderr, "Error: Failed to open %s for writing: %s\n",
@@ -512,12 +513,17 @@ mnemon_save (mnemon_t *mnemon)
 
        category_print (category, file);
 
+       fclose (file);
+
        err = rename (lock_filename, filename);
        if (err < 0) {
            fprintf (stderr, "Error: Failes to rename %s to %s: %s\n",
                     lock_filename, filename, strerror (errno));
            continue;
        }
+
+       free (filename);
+       free (lock_filename);
     }
 }