Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp154442ybj; Wed, 6 May 2020 13:57:31 -0700 (PDT) X-Google-Smtp-Source: APiQypLJDJmfq3nSjY5HEUO0tYns6MOeP6MTTp1DXZoOY7A00bqKJAZvgYlPHzJEx7Q/jl0BzBts X-Received: by 2002:a05:6402:1651:: with SMTP id s17mr9167839edx.173.1588798651068; Wed, 06 May 2020 13:57:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588798651; cv=none; d=google.com; s=arc-20160816; b=vRqpQP+MeqVsxiZB2ojGOMh80eDYKmOnI9dwVF4hy5SICXU9MUF9oPRQ2ep7yTUTAL qzYh3vXVqlMZUMIpd9gy/m4FwK1wSJLm0rnFTqR1/pZBFNp5q0MXhvD/EHTIXnJKU/HF 1A40F38VczX4Pn7y+GjPhwCzT+BxydVLaLv2891+MgZJLW5MUobxKQ1GL1x1tCnNJXnl d/pE4Uscpno96xdeMc7h9KMi6NAhgtKePrbemufzq95UTsBPq25msdVg8u5wmlKIeVQL vrscRF/qCKZpXdrb34JWVWlfH0IeXFBy9coZ7X5XW2SDB2y5abmT3XgVm+fpJWEyoikG 25NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=SB+0qR8XBn8IFJQ/MG0Miycx8pxpjR3L5u9CDE0na6s=; b=KFLSsmhuk7E+B7N1r3Pe8yA7vMLEi5oQv8tQHsUiVmvZRunPGc7TNteFISxPxnShwR C6ADck7iasFeAfgiB3zLOi0dc8Mk0m3NwdyBEeAZSp+uw3PnAY4XAx7o1Ay7IUgx2YxM h6cnP8ZSXsk9nhWJmcAQ28NBFCdtLe4+Ham6ze50I40tUdkVW8vpcAO/MD4uQ4/yV+0A 5KwcvqkYJxtDnlJiWtQfom2SSNoE6aLyQDY7taTlqUU3G4BdNtYDDgK2lt/MhhRYm/9n Tz4MlQhrod1wbty8IgnCBaQIJ6ANq4pC6QkSeLKNG5gKKzyeFwW/26fsr5G59Iny1fd5 IQGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Xr+iZOjv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si1882523edr.16.2020.05.06.13.57.07; Wed, 06 May 2020 13:57:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Xr+iZOjv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729401AbgEFUxJ (ORCPT + 99 others); Wed, 6 May 2020 16:53:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729199AbgEFUxG (ORCPT ); Wed, 6 May 2020 16:53:06 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12D34C061BD3 for ; Wed, 6 May 2020 13:53:05 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 186so4181441ybq.1 for ; Wed, 06 May 2020 13:53:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=SB+0qR8XBn8IFJQ/MG0Miycx8pxpjR3L5u9CDE0na6s=; b=Xr+iZOjvxcNqSpKCGofVocwfNYahKeswTd3EUNRVcV6W1+/yk6KkvpVOHowLJgRnTQ +bm+jG/e2f0TpEX6VaspQ3/LKIOohlS4DZ++8/cjk/v9az6hCTs3spdYcclANMkZiUJu btxV+qnCtPj1EJlGIMCYVCcebOTMKbdwOxAthGT/iJXib711W+dOlmFgR/63Q4KCMH9e oCcVtnM8qQd0qqRA4Oq5laRGzDKX2NFtzoUOjys9BfzK3a2DXZpH9C1YgZ7XebptGl6x Wl1uyB+UjheCRiRevb5m+IiXrOQv1LUxb7q8yiRFdFPCFwyFKgmoxpZKS90b9TYrDPiN Ae+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SB+0qR8XBn8IFJQ/MG0Miycx8pxpjR3L5u9CDE0na6s=; b=S5SQuTbSTEWPXWZ7a5YCW8ahANOXegylKpSnyUJRuMcQCQLmGyTupPvk0lofypV9Jl EhA7N7HLsrUy92Ywmh01hBDLrQY1UorSx0MOmKpc/MJjEhN4hfB6DCnMMxymN3Q935nj Fek+WhAeiUMjTmVJ5rB15gRnfLXE91t+boRWMSWGHzYshbnh4c6eeisr1eeZSOraLqSG RW+oStHfEVcAoF4MYMpBRUF7tIMz84NSgKkpmce46+ke3i3MXGr4JbY4PfzK6VfT/mU+ 47E9SpnmNGxERDiApGYgiv+CzE07pmjNYZ9H5cVxmflMkbhzj6WPSNwRmydVc/WqQYIN 8+3w== X-Gm-Message-State: AGi0PuZWgaClTS83LSV2h/skGuAwj3L2hFpn1rVwUVp5bynBOALv1zZ2 OFss9BY8+JAg0JVdOiVsVb88N5N/VbBo X-Received: by 2002:a25:9384:: with SMTP id a4mr16176208ybm.79.1588798384256; Wed, 06 May 2020 13:53:04 -0700 (PDT) Date: Wed, 6 May 2020 13:52:57 -0700 In-Reply-To: <20200506205257.8964-1-irogers@google.com> Message-Id: <20200506205257.8964-3-irogers@google.com> Mime-Version: 1.0 References: <20200506205257.8964-1-irogers@google.com> X-Mailer: git-send-email 2.26.2.526.g744177e7f7-goog Subject: [PATCH 2/2] lib/bpf hashmap: fixes to hashmap__clear From: Ian Rogers To: Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org hashmap_find_entry assumes that if buckets is NULL then there are no entries. NULL the buckets in clear to ensure this. Free hashmap entries and not just the bucket array. Signed-off-by: Ian Rogers --- tools/lib/bpf/hashmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/lib/bpf/hashmap.c b/tools/lib/bpf/hashmap.c index 54c30c802070..1a1bca1ff5cd 100644 --- a/tools/lib/bpf/hashmap.c +++ b/tools/lib/bpf/hashmap.c @@ -59,7 +59,13 @@ struct hashmap *hashmap__new(hashmap_hash_fn hash_fn, void hashmap__clear(struct hashmap *map) { + struct hashmap_entry *cur, *tmp; + size_t bkt; + + hashmap__for_each_entry_safe(map, cur, tmp, bkt) + free(cur); free(map->buckets); + map->buckets = NULL; map->cap = map->cap_bits = map->sz = 0; } -- 2.26.2.526.g744177e7f7-goog