]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch setup: Fix a couple of error paths.
authorCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2009 21:55:02 +0000 (14:55 -0700)
committerCarl Worth <cworth@cworth.org>
Fri, 23 Oct 2009 21:55:02 +0000 (14:55 -0700)
We had early returns instead of goto statments, and sure enough,
they were leaking. Much cleaner this way.

notmuch.c

index 279d21a58013be7cff1e5547d42addd35034e3f8..d21e4f5a628d897fe5d5d013638fe841d6b37e8f 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -266,13 +266,14 @@ count_files (const char *path, int *count)
 int
 setup_command (int argc, char *argv[])
 {
 int
 setup_command (int argc, char *argv[])
 {
-    notmuch_database_t *notmuch;
-    char *mail_directory, *default_path;
+    notmuch_database_t *notmuch = NULL;
+    char *default_path, *mail_directory = NULL;
     size_t line_size;
     int count;
     add_files_state_t add_files_state;
     double elapsed;
     struct timeval tv_now;
     size_t line_size;
     int count;
     add_files_state_t add_files_state;
     double elapsed;
     struct timeval tv_now;
+    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
 
     printf ("Welcome to notmuch!\n\n");
 
 
     printf ("Welcome to notmuch!\n\n");
 
@@ -298,7 +299,6 @@ setup_command (int argc, char *argv[])
     printf ("Top-level mail directory [%s]: ", default_path);
     fflush (stdout);
 
     printf ("Top-level mail directory [%s]: ", default_path);
     fflush (stdout);
 
-    mail_directory = NULL;
     getline (&mail_directory, &line_size, stdin);
     chomp_newline (mail_directory);
 
     getline (&mail_directory, &line_size, stdin);
     chomp_newline (mail_directory);
 
@@ -328,8 +328,8 @@ setup_command (int argc, char *argv[])
     if (notmuch == NULL) {
        fprintf (stderr, "Failed to create new notmuch database at %s\n",
                 mail_directory);
     if (notmuch == NULL) {
        fprintf (stderr, "Failed to create new notmuch database at %s\n",
                 mail_directory);
-       free (mail_directory);
-       return 1;
+       ret = NOTMUCH_STATUS_FILE_ERROR;
+       goto DONE;
     }
 
     printf ("OK. Let's take a look at the mail we can find in the directory\n");
     }
 
     printf ("OK. Let's take a look at the mail we can find in the directory\n");
@@ -355,11 +355,13 @@ setup_command (int argc, char *argv[])
     print_formatted_seconds (elapsed);
     printf (" (%d messages/sec.).                 \n", (int) (add_files_state.count / elapsed));
 
     print_formatted_seconds (elapsed);
     printf (" (%d messages/sec.).                 \n", (int) (add_files_state.count / elapsed));
 
-    notmuch_database_close (notmuch);
-
-    free (mail_directory);
+  DONE:
+    if (mail_directory)
+       free (mail_directory);
+    if (notmuch)
+       notmuch_database_close (notmuch);
     
     
-    return 0;
+    return ret;
 }
 
 int
 }
 
 int