Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3623120pxb; Mon, 24 Jan 2022 13:45:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2AbIZPV+kpZ5sySxfrGnhDXno+caspelAXy+K7lbP5mlEkowJzR/Y18faco4qJuPbMLKf X-Received: by 2002:a17:902:ed82:b0:14a:9ad8:a146 with SMTP id e2-20020a170902ed8200b0014a9ad8a146mr15988010plj.55.1643060625630; Mon, 24 Jan 2022 13:43:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643060625; cv=none; d=google.com; s=arc-20160816; b=kFHGncJWT+cMqyFQZ24gaEU2TG6FeAHYzBxL6egbRjm2ffWUaSVgt/1A0w+eS7Uvaf F/jHmT4QhcffZH0Rh2Bvpiw8iDfzXaigjE+8c3wIUh/IGvU1sAqXSS11qJycwWJFuZcr o0mfD1hUlMU6d5CLaTRbPIRdtdtnzRfP0T86ymzbAHcOIwhIncT6zQH58G4G2BgeSlvY EzpaRowyVprV57S4wra61f21H7o2WQltfRHobB37foGGxCx1RUjehPKM6lWlLf4KhQu9 L+IwTDr0grixWDq4+xk3DYPhvK+N3e7msJNUFqt/G0L2HEzLX2ElNzWs5PDduWemAYD+ DsmA== 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=bf4unsK/cf9MRuYDRpBF0f92YDz9veFhy0Pm+2Diow0=; b=ul3lkpISz0kv7WjTAZ3Bd70y5Qmbh5uXlPO5khl87L9qWOaGXykpPUiGiItjkr0sRb O3H/zSvN7M/IMlOaunJ3vtbT1tPhSzFuvnTZF4mIusyhBlJSAT2psavX85AfoxXG4vhs mAlfn0S8UYCkPJ9Hy+cTTpHg8gdUtLsjCswYJU4mzXTxyq0/Tchhe/008oE2WslHcsdw zi5LVuJI42ThTAjFIfY8U+yWDa8i4ZUtCMIRD9iIqWF5oFLmMm5PZy7HKuNmWBK7E9wF 9S3Tlb9uXIeK5VzJgiglbIih/ygPLBCrIr6u4s5gVHnjNnUMuvkKUeZ06YMDwxdNKhhb xhfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TIFpWiSC; 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 15si5065448pgc.694.2022.01.24.13.43.26; Mon, 24 Jan 2022 13:43: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=TIFpWiSC; 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 S1452279AbiAXVY3 (ORCPT + 99 others); Mon, 24 Jan 2022 16:24:29 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:50862 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353026AbiAXU6F (ORCPT ); Mon, 24 Jan 2022 15:58:05 -0500 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 dfw.source.kernel.org (Postfix) with ESMTPS id B5CEC61365; Mon, 24 Jan 2022 20:58:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90921C340E5; Mon, 24 Jan 2022 20:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643057884; bh=RO+5N/zhRhahqWndNfd+YsjyavI19TV9eMuwRXShToo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TIFpWiSCkkbm9r38mtPAp7mSTovnYEy7aKVudpVvgeOluvHWCW+B/D7GvcqnY2M5z GuTKR2dFSMExAQixtP3U9J/xtGdorTkHgZw9mXP91uTdARIMYyCrTKxJ6BEanVeMgP Kpq3bfuaq0mKHDlnU7i2/SUbNElUN3Vxr58ixcRk= 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.16 0110/1039] libbpf: Free up resources used by inner map definition Date: Mon, 24 Jan 2022 19:31:39 +0100 Message-Id: <20220124184128.836185058@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 5367bc8e52073..509f3719409bb 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9028,7 +9028,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