From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id iAhpFWzz2mF5bwEAgWs5BA (envelope-from ) for ; Sun, 09 Jan 2022 15:38:36 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id AEXHEWzz2mHcfwEAauVa8A (envelope-from ) for ; Sun, 09 Jan 2022 15:38:36 +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 E12B83A1F9 for ; Sun, 9 Jan 2022 15:38:35 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4BF975F723; Sun, 9 Jan 2022 14:38:18 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 655B35F5E1 for ; Sun, 9 Jan 2022 14:38:15 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id CE1425FC48; Sun, 9 Jan 2022 09:38:14 -0500 (EST) Received: (nullmailer pid 3682813 invoked by uid 1000); Sun, 09 Jan 2022 14:38:10 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH v2 3/4] lib/config: move g_key_File_get_string before continue Date: Sun, 9 Jan 2022 10:38:04 -0400 Message-Id: <20220109143805.3682660-4-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220109143805.3682660-1-david@tethera.net> References: <20220109143805.3682660-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: PTQSQCKG6NTTBXFF6GA6VL4IG6B2GZ3G X-Message-ID-Hash: PTQSQCKG6NTTBXFF6GA6VL4IG6B2GZ3G 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=1641739115; 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=tQ3Mn0X7fc+beEF5BBFSFwaU+SKfImZjokVcKDs80W8GR5wk+oEWc3AgfjEOE7/eQbuYGD RIwaM05P9x+T7byDRiAQr0ppfAsqhGn574/X6Z80vo27akg3UFBJzA+2JIxhWAXEVAdHak xHU0UHklRDmGqECMqVN6omajO/RuuxkxgXE3XP1nL22Im1ktazUBl85nOCWkWPE+0Dr+Qb JNT+KFcdE70qYehq0ozhTZFMWvAyzgRx0BL3ER8QKj7NXO7+bZcNdr9EVrB30G1YW+pky1 Rzq4TQH99mTIFTfUKPEdbm6Q36W/OjLtHiff4hW2YDgvcU9MIqf2aHv2R1zT2g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641739115; a=rsa-sha256; cv=none; b=pcznNcAFlXsaoXuQoi/bwA4TpLFZ2k70NR/X4jcYn9VVRi1qnLK8jMpZ8IAESEXMP6Edxq E48BRVG6nLpqPBqyhjD3M94123bScGpYvY10ebrB5Dbrx/YcYomWy2hDTjRhslD2+ioDHR XvmRsp5FARs3la9qkYcylG4tkeYm0QklkMFwj6cqutah+46EZCpK4FouQsHu/01lCtwlG6 4f18RIkhA/06hji+rkwekfqSC7qP1XrK6rEiuhFoW2ms/V6ScF//NmULTtZx36Y6wpvtk5 /OREecT/ZUohsjGedCce4WXOjdfTEsCRhmf6pyWH//JlJijBCH5mfeDeQre4lQ== 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: -2.29 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: E12B83A1F9 X-Spam-Score: -2.29 X-Migadu-Scanner: scn0.migadu.com X-TUID: CM9HQqjRrdTt 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