From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 0JESDskMdGHOigAAgWs5BA (envelope-from ) for ; Sat, 23 Oct 2021 15:23:21 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 4CWHCckMdGFVMwAAbx9fmQ (envelope-from ) for ; Sat, 23 Oct 2021 13:23:21 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E143118C55 for ; Sat, 23 Oct 2021 15:23:20 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 0028A20233; Sat, 23 Oct 2021 09:23:05 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id D37672C1EA for ; Sat, 23 Oct 2021 09:22:57 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 66A575FC51; Sat, 23 Oct 2021 09:22:57 -0400 (EDT) Received: (nullmailer pid 1864490 invoked by uid 1000); Sat, 23 Oct 2021 13:22:52 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 6/6] lib/load_config: deallocate / NULL database on fatal error Date: Sat, 23 Oct 2021 10:22:38 -0300 Message-Id: <20211023132238.1864400-7-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211023132238.1864400-1-david@tethera.net> References: <20211023132238.1864400-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 66W5NOTEGLJ2YLTUOGFYT5LB75IUNX6E X-Message-ID-Hash: 66W5NOTEGLJ2YLTUOGFYT5LB75IUNX6E X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1634995401; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=OSjGkL3saeY0b4mHZ1NpGj+tHVVgeofLd+bhHurCOGM=; b=RCpMFebGPsl8oPamst6HjpMssDSnXe6KhdF1sqdXEnYz31o+YzQavLh8zF68ke51hlgDMO O5rdHevKpnZM/Fh3O62eDR4t3GCxH3dwbUb8XRA3n4ae6yebOOsppi1QT6epoJ7dPTxHK8 mAMPJyfwJllUrQ06B+Riw+vBz4Oihdy+uHdnPttncoPUMjlB4wBvUgrLL68suRUsN+JfE6 UNkLb/H8btkf+vTMi6bTp4VjOsi9nKfv14dKBs9Vk/en+d1VJo5+NCwSVkcwNBLPRpHzuz S+46O2rNSMh8DTvX+4E5TuTBT2UgESulFtjDYodYcKXqOrg7MJgIIW5gEnpKfA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1634995401; a=rsa-sha256; cv=none; b=N7sRQ5iCG9MI1ClX4QSWopLcLjCCHnD7H+l7I2U0XaYSOVpep1x2RTYub/L9pgjSTpop1d Utd8WOJOq8ii/MqNeH2s5OLHADJkyUEvKgbCGHPFx9hJLB3W3uuYPeq79IGzErrWw0QKfS YSoGV/psazlqMUioYAEjizSzfMIiCjz4mzm4rF52wh21qfAug3kKXE7BHdN48O7qZnF4sY gi/WKFcuUfnNtkKk7MZ2jwSTe0ccVYAWNN+0Oqj6SuiYfhqNn/X/Afo1YbLmUe3sAgFmiC moXsEixfDsfqj0EQegafXyg8+z+9JKf1NIqzzH7xWidNwLJHWcMDj2oTu2mmlQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.15 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: E143118C55 X-Spam-Score: -1.15 X-Migadu-Scanner: scn0.migadu.com X-TUID: t/fWy8GPjCDm 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