From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id MJdvMgPY2WEwIgAAgWs5BA (envelope-from ) for ; Sat, 08 Jan 2022 19:29:23 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id qGUhKwPY2WFz7AAAG6o9tA (envelope-from ) for ; Sat, 08 Jan 2022 19:29:23 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7734E1B478 for ; Sat, 8 Jan 2022 19:29:23 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 5D6905F721; Sat, 8 Jan 2022 18:29:19 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id C6E7A5F717 for ; Sat, 8 Jan 2022 18:29:16 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id EE1C45FC42; Sat, 8 Jan 2022 13:29:15 -0500 (EST) Received: (nullmailer pid 3147619 invoked by uid 1000); Sat, 08 Jan 2022 18:29:14 -0000 From: David Bremner To: Austin Ray , notmuch@notmuchmail.org Subject: [PATCH 1/2] lib/config: move g_key_File_get_string before continue Date: Sat, 8 Jan 2022 14:28:43 -0400 Message-Id: <20220108182844.3147598-1-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220105224538.m36lnjn7rf3ieonc@athena> References: <20220105224538.m36lnjn7rf3ieonc@athena> MIME-Version: 1.0 Message-ID-Hash: PSAPX7HA26LNMFZP5URUAKFQVVQWCEXF X-Message-ID-Hash: PSAPX7HA26LNMFZP5URUAKFQVVQWCEXF 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; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641666563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to: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-owner:list-unsubscribe:list-subscribe:list-post; bh=H0T4xtplQDCxQnj22ZItVeuqBI2Ztj06yVL51YBV9vM=; b=t3DrHX1OQpl9/qynPWhAs4Dy438ZylypWLMjbPSzPAuz7jP80BBddcwaEyuwQRTI5DrkZG l3qbC9aLJoFwqC2JhV8u4HlgowWfdi82cUTnvkesgiXmkDVe23xKYRvEAXtSMKzT88WnNU zUXFUiLgCLCvu7TGPrKkITm0YC88JuAqfM4Txc+w2quVucndn8KVPZnIjH7RJkost30x86 HtTXvewlX5fY33v/tDFULrqc9Y3fZP0WU1NWK6n0vplJSJjFcH8jTL3kW2zEk6hZaC0xcd qsv+7YWyEJi29jwVJiqtTBvSyx3dBPDXQXH45FvcS5O0TmEaAeZ2CG4S9U0aLA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641666563; a=rsa-sha256; cv=none; b=PELgZmkNJvHDK+VDTeocJkME2c00mzVWrYglO45ifw1adczv7BfmAZS0hwPgtfcS9cWYCo 3Fu2eBW+2VUd6kE13yzJnM9AaSAdEc1KoJiC3IuG3lBo5KTooqosXiwg39qZgkx4QnVtS1 zE8oCtaeuyjf7xzQx122am0pHgJyTfcxEHl5GBnBwJER0YztW0e/4ntF3uLNA8B0IyXv4p 2WNm0mCzihq6mWrktGXs62dNmTvafyeXkat0IpDq0y/1R3nsoR7S5OOm6mp5nsd/5PrEH1 ZgGkCN8elCv5bkZB5a3iWlKS7G+gvG8WNVXfDmufMfnIFe9AMuE6IPMT5ILGEQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.79 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 7734E1B478 X-Spam-Score: -1.79 X-Migadu-Scanner: scn0.migadu.com X-TUID: 7fW1PGfEJAjw In [1] Austin Ray reported some memory leaks in notmuch_database_open. One of those leaks is caused by jumping to the next key without freeing val. This change avoids that leak. [1]: id:20220105224538.m36lnjn7rf3ieonc@athena --- lib/config.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/config.cc b/lib/config.cc index 7a2882de..b9e11a54 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -435,11 +435,6 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, for (gchar **keys_p = keys; *keys_p; keys_p++) { char *absolute_key = talloc_asprintf (notmuch, "%s.%s", *grp, *keys_p); char *normalized_val; - val = g_key_file_get_string (file, *grp, *keys_p, NULL); - if (! val) { - status = NOTMUCH_STATUS_FILE_ERROR; - goto DONE; - } /* If we opened from a given path, do not overwrite it */ if (strcmp (absolute_key, "database.path") == 0 && @@ -447,6 +442,12 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, notmuch->xapian_db) continue; + val = g_key_file_get_string (file, *grp, *keys_p, NULL); + if (! val) { + status = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; + } + normalized_val = _expand_path (notmuch, absolute_key, val); _notmuch_string_map_set (notmuch->config, absolute_key, normalized_val); g_free (val); -- 2.34.1