]> git.notmuchmail.org Git - notmuch/blobdiff - lib/database.cc
lib: Release resources if notmuch_database_open fails
[notmuch] / lib / database.cc
index 8103bd96ef88c0e30f256753145f17f5583118a2..94022d7ce3ae9c060ecf18baaca1aa95afa11781 100644 (file)
@@ -617,7 +617,7 @@ notmuch_database_open (const char *path,
        initialized = 1;
     }
 
-    notmuch = talloc (NULL, notmuch_database_t);
+    notmuch = talloc_zero (NULL, notmuch_database_t);
     notmuch->exception_reported = FALSE;
     notmuch->path = talloc_strdup (notmuch, path);
 
@@ -703,6 +703,7 @@ notmuch_database_open (const char *path,
     } catch (const Xapian::Error &error) {
        fprintf (stderr, "A Xapian exception occurred opening database: %s\n",
                 error.get_msg().c_str());
+       notmuch_database_close (notmuch);
        notmuch = NULL;
     }