From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KJ6HL5GIQ2AEeAAA0tVLHw (envelope-from ) for ; Sat, 06 Mar 2021 13:50:09 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id UGiZK5GIQ2CgUgAA1q6Kng (envelope-from ) for ; Sat, 06 Mar 2021 13:50:09 +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) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 738CCA008 for ; Sat, 6 Mar 2021 14:50:09 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 684DB2758D; Sat, 6 Mar 2021 08:49:47 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id B1B8226BF0 for ; Sat, 6 Mar 2021 08:49:41 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id A913B5FA96; Sat, 6 Mar 2021 08:49:41 -0500 (EST) Received: (nullmailer pid 491407 invoked by uid 1000); Sat, 06 Mar 2021 13:49:37 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 3/4] lib/config: free memory from traversing GKeyFile Date: Sat, 6 Mar 2021 09:49:33 -0400 Message-Id: <20210306134934.491249-4-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210306134934.491249-1-david@tethera.net> References: <20210306134934.491249-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: JY2UYBDTTYBDBYTU36FMKPBK253GTZYP X-Message-ID-Hash: JY2UYBDTTYBDBYTU36FMKPBK253GTZYP 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=1615038609; 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=T85iM7rnNSnBvFHt6BAY71oYR6RsqWvXr0V1v5X9LKA=; b=F6/Etx1gyX9nB3IvPUXDO6vIp1O+rt1vQM/PktvusQxr18GQ6lKOjGMvtWK++yVkaKwlpp 3W/wJkTEQ4qWo82woatrEal6svKRPkFQ/rcayVUsyykTutiYCDDwC72L6vuIBYTK3vWMO0 Zy/f56LXBCIm9sPIwa/imB9Br3nsXcQokn46SjQncl4ZPqd8ASAJ5xthpD5oFAar7kUcTP N/1bsD7PI9z0cWNZlBw7ofAUT2p3YrBjuuCZ0HbzD1nkmN7up1lfV3IPu6ls59QEuibQK8 4yRCQhv/0QSBbhFuxk0UZWQDw/ZoH8C62KTCWYTcTJNesPgh8Pe0RVce5TlEeA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615038609; a=rsa-sha256; cv=none; b=EQSTvrHhGP1TnMJkXHatOKA9rmj+1G6+j7wW56H2Yxn8zaOAYvzYSBWXwvtf3Ia4uBtACm HYovJW9RJNQdm9bZCxWWOsgSzdma5yHNrPtDZbrO7Z+qL6beRvmTfbWpV7Zxz97VCIUDe2 vUgngOcXgiSqip1vS4u8SAgGGdYJnoQEafduvZaD5tcENBT5u4QMqH4uhI6VnopJfDs6mP hfbHh7fywY68W5GLhN5CxkFuDxfyrp+qN1enWEhCp8tfWMSikNhJISEQ4vpaU9ftBVNbix ZNmvatvD8I9oRNRHucGPoOM3HNxnTSKVKLoQ4sooILDlYdeYZFVMDtunXH+KDA== 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: -0.96 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: 738CCA008 X-Spam-Score: -0.96 X-Migadu-Scanner: scn0.migadu.com X-TUID: zwLjId7Sg8xf This fixes a few small memory leaks. --- lib/config.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/config.cc b/lib/config.cc index 948751bc..6ace6e52 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -330,7 +330,7 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, GKeyFile *file) { notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; - gchar **groups, **keys, *val; + gchar **groups = NULL, **keys, *val; if (notmuch->config == NULL) notmuch->config = _notmuch_string_map_create (notmuch); @@ -340,22 +340,29 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, goto DONE; } - for (groups = g_key_file_get_groups (file, NULL); *groups; groups++) { - for (keys = g_key_file_get_keys (file, *groups, NULL, NULL); *keys; keys++) { - char *absolute_key = talloc_asprintf(notmuch, "%s.%s", *groups, *keys); - val = g_key_file_get_value (file, *groups, *keys, NULL); + groups = g_key_file_get_groups (file, NULL); + for (gchar **grp=groups; *grp; grp++) { + keys = g_key_file_get_keys (file, *grp, NULL, NULL); + for (gchar **keys_p = keys; *keys_p; keys_p++) { + char *absolute_key = talloc_asprintf(notmuch, "%s.%s", *grp, *keys_p); + val = g_key_file_get_value (file, *grp, *keys_p, NULL); if (! val) { status = NOTMUCH_STATUS_FILE_ERROR; goto DONE; } _notmuch_string_map_set (notmuch->config, absolute_key, val); + g_free (val); talloc_free (absolute_key); if (status) goto DONE; } + g_strfreev (keys); } DONE: + if (groups) + g_strfreev (groups); + return status; } -- 2.30.1