From patchwork Fri Nov 20 00:17:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1403403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CccbP4lVpz9sTL for ; Fri, 20 Nov 2020 11:18:41 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2E49D2D63B; Fri, 20 Nov 2020 00:18:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZTMMRjevaK+i; Fri, 20 Nov 2020 00:18:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 458C82E0D7; Fri, 20 Nov 2020 00:18:05 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1D921C1825; Fri, 20 Nov 2020 00:18:05 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id E0060C0891 for ; Fri, 20 Nov 2020 00:18:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id CD46986D22 for ; Fri, 20 Nov 2020 00:18:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id p9P02VdhDlPB for ; Fri, 20 Nov 2020 00:18:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by fraxinus.osuosl.org (Postfix) with ESMTPS id C0D8985C9D for ; Fri, 20 Nov 2020 00:18:01 +0000 (UTC) X-Originating-IP: 78.45.89.65 Received: from im-t490s.redhat.com (ip-78-45-89-65.net.upcbroadband.cz [78.45.89.65]) (Authenticated sender: i.maximets@ovn.org) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 7CB3B240006; Fri, 20 Nov 2020 00:17:59 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Fri, 20 Nov 2020 01:17:16 +0100 Message-Id: <20201120001724.2424494-7-i.maximets@ovn.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201120001724.2424494-1-i.maximets@ovn.org> References: <20201120001724.2424494-1-i.maximets@ovn.org> MIME-Version: 1.0 Cc: Ilya Maximets Subject: [ovs-dev] [PATCH ovn 06/14] pinctrl: Fix leak of DNS cache records. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 'smap_clear()' doesn't free allocated memory, but 'smap_clone()' re-initializes hash map clearing internal pointers and leaking this memory. 'smap_destroy()' should be used instead. Also, all the records and array of datapaths should be freed on destruction of a cache entry. Direct leak of 16 byte(s) in 2 object(s) allocated from: #0 0x5211c7 in calloc (/controller/ovn-controller+0x5211c7) #1 0x752364 in xcalloc /lib/util.c:121:31 #2 0x576e76 in sync_dns_cache /controller/pinctrl.c:2517:25 #3 0x5758fb in pinctrl_run /controller/pinctrl.c:3158:5 #4 0x59b06c in main /controller/ovn-controller.c:2642:25 #5 0x7fb570fc11a2 in __libc_start_main (/lib64/libc.so.6+0x271a2) Indirect leak of 26 byte(s) in 2 object(s) allocated from: #0 0x52100f in malloc (/controller/ovn-controller+0x52100f) #1 0x7523d6 in xmalloc /lib/util.c:138:15 #2 0x7524a8 in xmemdup0 /lib/util.c:168:15 #3 0x73d8fc in smap_clone /lib/smap.c:314:45 #4 0x576e2f in sync_dns_cache /controller/pinctrl.c:2513:13 #5 0x5758fb in pinctrl_run /controller/pinctrl.c:3158:5 #6 0x59b06c in main /controller/ovn-controller.c:2642:25 #7 0x7fb570fc11a2 in __libc_start_main (/lib64/libc.so.6+0x271a2) Fixes: 6b72068202f1 ("ovn-controller: Add a new thread in pinctrl module to handle packet-ins.") Signed-off-by: Ilya Maximets --- controller/pinctrl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/controller/pinctrl.c b/controller/pinctrl.c index a5236564b..2012ba65a 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -2509,7 +2509,7 @@ sync_dns_cache(const struct sbrec_dns_table *dns_table) dns_data->delete = false; if (!smap_equal(&dns_data->records, &sbrec_dns->records)) { - smap_clear(&dns_data->records); + smap_destroy(&dns_data->records); smap_clone(&dns_data->records, &sbrec_dns->records); } @@ -2525,6 +2525,8 @@ sync_dns_cache(const struct sbrec_dns_table *dns_table) struct dns_data *d = iter->data; if (d->delete) { shash_delete(&dns_cache, iter); + smap_destroy(&d->records); + free(d->dps); free(d); } } @@ -2537,6 +2539,8 @@ destroy_dns_cache(void) SHASH_FOR_EACH_SAFE (iter, next, &dns_cache) { struct dns_data *d = iter->data; shash_delete(&dns_cache, iter); + smap_destroy(&d->records); + free(d->dps); free(d); } }