[PATCH 6/6] lib/load_config: deallocate / NULL database on fatal error

Subject: [PATCH 6/6] lib/load_config: deallocate / NULL database on fatal error

Date: Sat, 23 Oct 2021 10:22:38 -0300

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


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            | 7 +++++++
 test/T590-libconfig.sh | 1 -
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/open.cc b/lib/open.cc
index 6fa00a84..ba32c2f1 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -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;
 
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index e6bec872..7feb6519 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -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
-- 
2.33.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: