Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3992027pxb; Tue, 25 Jan 2022 00:52:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJyUcSLwuAp0dRSPLMipZCKkmgz074O8/f98LtWxB2YYr69VKWqeJM0UsaliEm1nQEGSWWvf X-Received: by 2002:a17:906:4fcc:: with SMTP id i12mr3207137ejw.530.1643100778078; Tue, 25 Jan 2022 00:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643100778; cv=none; d=google.com; s=arc-20160816; b=Xnh6m4HQGQC8uYet5zL63A1kmvpxQJqWcWQHNwNh6QVJGIj0sIZ2tJvCyGqd20SW/h 0JwvRcMaREHHNqCfpr83EnIxpcc9kChvsdtEeegr0rEzBPncEj4wbpeQGdWIMwD25Iz5 hciPJPdVW0cPQDUEhV679DAc3X5Z/grh9oeFhUCKiuTgIeoShBY1eVE4a8y8tsb7NoWy SmrEWHCtBp7NnOQBr6PS3vAIVff/Fjnwio2WKrTu4gwvQ1r+L3oF8jrOJ1MeyR7FuDTF ZH8VpznAfh5SMO6YitGrdJ33HFMXy0jy0s78j6Hhm94FvJzcvdDcoessTHMfPT439+1L 3v3w== 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=YieScrjl0HSZ/TaqKbv6FEX/5o6TiyzTfvQJ3trDJ1Q=; b=E0w5rBjP5dxELgb9PP3xXf3Hk9qozumab8/xa+w1DnYbcfhfRFRMGvlmlt3Hg9H+fm ELxjLu1YFT2lHwBTiEfse7zVdTqdLFM1G+OeRGWz1zLdJAEwq6w9sF1a0FIto7gLao7H 65QVsuo/yLfJzIhbFBfblqX+xJR9SlPp5Gjg0z+z5Bsa9m19rTZUeCSAJ75EweO62cdS SiDrHIFyaYCliaIyoc3tAhwQ1Syhq4jfSr2+ItHVhUBd52b/xaJDSIdvHVRNRM5ORgiS x0pDDA3nog7K7V2629KfryjLmYuT+Db3m4upI4tYwYUvddgatNOgfgl60OG4uO+rhLhj d6qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VXBnwyzb; 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 b12si11112624edd.411.2022.01.25.00.52.28; Tue, 25 Jan 2022 00:52:58 -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=VXBnwyzb; 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 S247543AbiAYEpu (ORCPT + 99 others); Mon, 24 Jan 2022 23:45:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1325574AbiAYDhr (ORCPT ); Mon, 24 Jan 2022 22:37:47 -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 7171FC0811AD; Mon, 24 Jan 2022 12:33:09 -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 3A728B81229; Mon, 24 Jan 2022 20:33:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E08CC340E5; Mon, 24 Jan 2022 20:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056387; bh=xSjM7sQ/q68pyXWnObsGO6CNownTJ0gLgJiruFyMyig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VXBnwyzbIHwl6L8iMtNJKDl7qiNsg18pcPzw2jKgCKdRZEvOT2VsNhdM7UjTQcAYk od3ZAmGHHdONvF7dK/NWj6Rv7r6TA/AyohaXh+Xln+7v4/6BUW6SWs2V8XAjtFe1W5 wAKseeDt5RFOu1DiQLHgBtZ+LrlqUbpxm2CLc/Bg= 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 466/846] selftests/bpf: Fix memory leaks in btf_type_c_dump() helper Date: Mon, 24 Jan 2022 19:39:43 +0100 Message-Id: <20220124184117.052223356@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 8ba285874913da21ca39a46376e9cc5ce0f45f94 ] Free up memory and resources used by temporary allocated memstream and btf_dump instance. Signed-off-by: Andrii Nakryiko Signed-off-by: Alexei Starovoitov Reviewed-by: Hengqi Chen Link: https://lore.kernel.org/bpf/20211107165521.9240-4-andrii@kernel.org Signed-off-by: Sasha Levin --- tools/testing/selftests/bpf/btf_helpers.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c index b692e6ead9b55..0a4ad7cb2c200 100644 --- a/tools/testing/selftests/bpf/btf_helpers.c +++ b/tools/testing/selftests/bpf/btf_helpers.c @@ -246,18 +246,23 @@ const char *btf_type_c_dump(const struct btf *btf) d = btf_dump__new(btf, NULL, &opts, btf_dump_printf); if (libbpf_get_error(d)) { fprintf(stderr, "Failed to create btf_dump instance: %ld\n", libbpf_get_error(d)); - return NULL; + goto err_out; } for (i = 1; i <= btf__get_nr_types(btf); i++) { err = btf_dump__dump_type(d, i); if (err) { fprintf(stderr, "Failed to dump type [%d]: %d\n", i, err); - return NULL; + goto err_out; } } + btf_dump__free(d); fflush(buf_file); fclose(buf_file); return buf; +err_out: + btf_dump__free(d); + fclose(buf_file); + return NULL; } -- 2.34.1