]> git.cworth.org Git - notmuch/blobdiff - lib/database.cc
lib: do not leak the database in compaction
[notmuch] / lib / database.cc
index 3dfea0f4f9e27b48de199ed539f0d58e8614b684..eadf8a763395187afccd18cefad47e1cca8d2650 100644 (file)
@@ -863,13 +863,17 @@ notmuch_database_compact (const char* path,
                          const char* backup_path,
                          notmuch_compact_status_cb_t status_cb)
 {
-    void *local = talloc_new (NULL);
+    void *local;
     char *notmuch_path, *xapian_path, *compact_xapian_path;
     char *old_xapian_path = NULL;
     notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
     notmuch_database_t *notmuch = NULL;
     struct stat statbuf;
 
+    local = talloc_new (NULL);
+    if (! local)
+       return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
     ret = notmuch_database_open(path, NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch);
     if (ret) {
        goto DONE;
@@ -937,10 +941,12 @@ notmuch_database_compact (const char* path,
        goto DONE;
     }
 
-    notmuch_database_close(notmuch);
-
 DONE:
+    if (notmuch)
+       notmuch_database_destroy (notmuch);
+
     talloc_free(local);
+
     return ret;
 }
 #else