Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3635873pxb; Mon, 24 Jan 2022 14:04:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxH1xQK+fHVb8p23lJa03hFeXt7UwuVXtq/V4wR3PiMc9u19f+f5vhT4Oaux9T2+wj1wFGE X-Received: by 2002:a05:6a00:a90:b0:4bd:320a:d579 with SMTP id b16-20020a056a000a9000b004bd320ad579mr15806010pfl.47.1643061885415; Mon, 24 Jan 2022 14:04:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061885; cv=none; d=google.com; s=arc-20160816; b=RAZQDYwU5+icDZUUoQIr4FCKuBA7UA4b7tClReZkL/Ad/G843+xm2DEZz8Z/311DPs xWJlymRJV0giN10HM+cUvC6wY7OStrAqMx4HoZADKmzoUwv6HWbyN8pxJMZYahLxLP9G NJRmz8bToH41FCQUqPPSF9NTf/M59bbFRow9n5EfrID3mNCkflPvsA+B8eo8Bxvwu0Gs t0icw2/TdzaiYqrk5/gaILHaOutJfnX3bxTrU9N1jE5hNPpnhUiwpCZ82OmEDAIonm0C hxRNhrKiDsEe2zj1oQC6SEGEYU3rBGbUhvBry2KbZVFoJSCKgi0r8IW4VKRWJ/Ky7lUe 4nGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5zHp8xtMVuSEmuibyv+Yhg0KIMyp+lymabdGEeo/DSE=; b=h6iR3oK+zlEU9mdtmo3yCReyRKRej9U7R82nPhTumVl8tOYEbn4ERQuPYLpf5DlV29 3qKOiw/5a90kfoBx4tfs0wGxzHR2nzGOO5iWrFwwGnBpwa1FDSFM8w0UoJlvl7eCIOHs IGqhsfYh9s/30igsCPc0GD8ZZ/kPRwLD0HY2p231D88vMctGuV4jajsx4sOZuQW7+cLu H41edJsLtUKYDOZHrqRroD4YlByz5bGaEqW4raAYVk2+/UGaaVocqK6NX4M3DNhmNJOQ j8bsi7U2JtJ4ROatwuSdHvAioicybSqJoRbRVh3XcJerlTkRSgq6ikpk9yeT75ANQWYR xPMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ui4xB5DU; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g9si14214776pgc.513.2022.01.24.14.04.33; Mon, 24 Jan 2022 14:04:45 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=ui4xB5DU; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1576335AbiAXVxW (ORCPT + 99 others); Mon, 24 Jan 2022 16:53:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1450655AbiAXVVI (ORCPT ); Mon, 24 Jan 2022 16:21:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5428FC0A1CC7; Mon, 24 Jan 2022 12:14:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 08674B812A5; Mon, 24 Jan 2022 20:14:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CAE2C340E7; Mon, 24 Jan 2022 20:14:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055276; bh=1XugZksY2Q1RIc5Ov3cpXwUMSko7XlkqMP6r64FLYaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ui4xB5DUYphgvhlHiOHh9Pb8xGCwdoroSqhtmwUejApUHTQfmIWvWegyxlNAoiGNV pvD1FKHb6jRtG7IoAWuHd3+ygNcg0l6+tXORHaEVMroQls/lu+avi3W2D0PJqaHGOe 0yu/RaHv88IbIhcn2ZMR/1TTaQmBm87CvcWDTsME= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , Alexei Starovoitov , Hengqi Chen , Sasha Levin Subject: [PATCH 5.15 098/846] libbpf: Free up resources used by inner map definition Date: Mon, 24 Jan 2022 19:33:35 +0100 Message-Id: <20220124184104.375758757@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrii Nakryiko [ Upstream commit 8f7b239ea8cfdc8e64c875ee417fed41431a1f37 ] It's not enough to just free(map->inner_map), as inner_map itself can have extra memory allocated, like map name. Fixes: 646f02ffdd49 ("libbpf: Add BTF-defined map-in-map support") Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Reviewed-by: Hengqi Chen Link: https://lore.kernel.org/bpf/20211107165521.9240-3-andrii@kernel.org Signed-off-by: Sasha Levin --- tools/lib/bpf/libbpf.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 7145463a4a562..0ad29203cbfbf 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -8676,7 +8676,10 @@ int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd) pr_warn("error: inner_map_fd already specified\n"); return libbpf_err(-EINVAL); } - zfree(&map->inner_map); + if (map->inner_map) { + bpf_map__destroy(map->inner_map); + zfree(&map->inner_map); + } map->inner_map_fd = fd; return 0; } -- 2.34.1