]> git.notmuchmail.org Git - notmuch/commitdiff
lib/load_config: deallocate / NULL database on fatal error
authorDavid Bremner <david@tethera.net>
Sat, 23 Oct 2021 13:22:38 +0000 (10:22 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 30 Oct 2021 16:51:50 +0000 (13:51 -0300)
This fixes a potential memory leak, and makes the behaviour of
notmuch_database_load_config (somewhat) consistent with
n_d_{open,create} with config.

lib/open.cc
test/T590-libconfig.sh

index 6fa00a843b9201d5bdf56dd15b3139e7e5adb8ec..ba32c2f16d84d9d19c5bdcf1e5ad58db76d411d7 100644 (file)
@@ -871,6 +871,13 @@ notmuch_database_load_config (const char *database_path,
     if (status_string)
        *status_string = message;
 
+    if (status &&
+       status != NOTMUCH_STATUS_NO_DATABASE
+       && status != NOTMUCH_STATUS_NO_CONFIG) {
+       notmuch_database_destroy (notmuch);
+       notmuch = NULL;
+    }
+
     if (database)
        *database = notmuch;
 
index b4abbd78f09d9ea7e6a81574f199cd1a461111e7..8db51ed043753e8408cdfc519921dc1bc92dccb8 100755 (executable)
@@ -942,7 +942,6 @@ EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "load_config: database set to NULL on fatal error"
-test_subtest_known_broken
 cat c_head3 - c_tail3 <<'EOF' | test_C
   notmuch_status_t st = notmuch_database_load_config("relative", NULL, NULL, &db, NULL);
 EOF