]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch restore: Fix leak of FILE* object.
authorCarl Worth <cworth@cworth.org>
Mon, 26 Oct 2009 16:20:32 +0000 (09:20 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 26 Oct 2009 20:36:40 +0000 (13:36 -0700)
Apparently, I didn't copy enough of the "notmuch dump" implementation
since it didn't have a similar leak.

notmuch.c

index 5ab155e51f930aad9ed789fd714c6a560b823aa2..e2347524506192b892bfd578faa2e5ed55d575b1 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -668,7 +668,7 @@ show_command (unused (int argc), unused (char *argv[]))
 static int
 dump_command (int argc, char *argv[])
 {
 static int
 dump_command (int argc, char *argv[])
 {
-    FILE *output;
+    FILE *output = NULL;
     notmuch_database_t *notmuch = NULL;
     notmuch_query_t *query;
     notmuch_message_results_t *results;
     notmuch_database_t *notmuch = NULL;
     notmuch_query_t *query;
     notmuch_message_results_t *results;
@@ -735,7 +735,7 @@ dump_command (int argc, char *argv[])
   DONE:
     if (notmuch)
        notmuch_database_close (notmuch);
   DONE:
     if (notmuch)
        notmuch_database_close (notmuch);
-    if (output != stdout)
+    if (output && output != stdout)
        fclose (output);
 
     return ret;
        fclose (output);
 
     return ret;
@@ -744,7 +744,7 @@ dump_command (int argc, char *argv[])
 static int
 restore_command (int argc, char *argv[])
 {
 static int
 restore_command (int argc, char *argv[])
 {
-    FILE *input;
+    FILE *input = NULL;
     notmuch_database_t *notmuch = NULL;
     char *line = NULL;
     size_t line_size;
     notmuch_database_t *notmuch = NULL;
     char *line = NULL;
     size_t line_size;
@@ -845,6 +845,8 @@ restore_command (int argc, char *argv[])
        free (line);
     if (notmuch)
        notmuch_database_close (notmuch);
        free (line);
     if (notmuch)
        notmuch_database_close (notmuch);
+    if (input && input != stdin)
+       fclose (input);
 
     return ret;
 }
 
     return ret;
 }