Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp297963rwi; Sun, 9 Oct 2022 23:50:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7KXTts1mjLsdf4v8TsSVX0hacsRoWUHOCaJ211x4FtJC0PlWePwFjNPMjOzJY3ESS05hMX X-Received: by 2002:a17:907:9625:b0:78d:bb06:9072 with SMTP id gb37-20020a170907962500b0078dbb069072mr1600609ejc.472.1665384634141; Sun, 09 Oct 2022 23:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665384634; cv=none; d=google.com; s=arc-20160816; b=kh+q4K7KLub+0kUbLUCQ43sgGcXNijTfn2fD2dm8ZUo2OnloQRPgx5uRpCyKszfTEd JA2CBkc7SN75GVgjHe5k+TWN1dD8Nb60iDEKyhJqL6uPWe63COogxUt52snZv7N4VJkh Xk6ARLDo3XccUjvbGptC87SHjbf/GcRCfsAV3LpUBhyDZJeMvjLK1ZTWXpVuUOX2CGKt q+X3uwlnHghYWqTep+3U82Qm6gd2pbf5/8as+Ps90/FlbsRFXWK70gmTWTmXqlyqvt78 3IH6P6wFJSzbbVoczOiKZfyoOthS+LbE1NB9tmrASq3j2j1C4Ku1kAdMGpnywkLtPGfQ huXg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qNEq2Ud7N+FC5y+X8B4NvGkEA5REdJ5eGaumfQx5am4=; b=pHSghdmXuJeQ5ar/FTfhiYUvdHbUhqDH8mkAA1ulZhz8vKpLGqe/ijEhdpFG69UFyo 27POjH8HudBL5Ic7/Oi4nrWxdC7bJOpBqzgXVRsOmKjilZijodcpBTa3g5MDCZlM4E70 xsL9UMi9ee98g9HxE+s0mUo9eOrWzzetJwV2z5+2wZLh3KtgzEGo2WdkeG42KEuwXywX QsYuXwQV/alCkgj+V0Diwt/GhU8RDhvt4dILycYTg7/UyRxo+GQwZr0RYZ8xhuneFOma +yJZGZefp6mMWTvdtDn1TQc8R47XZ8NYtZcK5r00FscILk2eaczAkH9JsU43WZYZoRJ1 UyDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a50d543000000b00456eaa4fb1fsi8308394edj.223.2022.10.09.23.49.48; Sun, 09 Oct 2022 23:50:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231559AbiJJGrW (ORCPT + 99 others); Mon, 10 Oct 2022 02:47:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231218AbiJJGrH (ORCPT ); Mon, 10 Oct 2022 02:47:07 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBEA051A3B; Sun, 9 Oct 2022 23:47:05 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Mm8Xx1DtFzKJ9m; Mon, 10 Oct 2022 14:44:49 +0800 (CST) Received: from k01.huawei.com (unknown [10.67.174.197]) by APP2 (Coremail) with SMTP id Syh0CgDnf9Tiv0NjoL4qAA--.49036S5; Mon, 10 Oct 2022 14:47:04 +0800 (CST) From: Xu Kuohai To: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Mykola Lysenko , Shuah Khan , "David S . Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Hou Tao , Dmitrii Dolgov <9erthalion6@gmail.com>, Alan Maguire , Kumar Kartikeya Dwivedi , Lorenzo Bianconi Subject: [PATCH bpf v2 3/5] selftests/bpf: Fix memory leak caused by not destroying skeleton Date: Mon, 10 Oct 2022 03:04:52 -0400 Message-Id: <20221010070454.577433-4-xukuohai@huaweicloud.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221010070454.577433-1-xukuohai@huaweicloud.com> References: <20221010070454.577433-1-xukuohai@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgDnf9Tiv0NjoL4qAA--.49036S5 X-Coremail-Antispam: 1UD129KBjvJXoW7uFy3Cr4xWF4UAFWDJFy5Jwb_yoW8uw4fpa 48u34akF1SyF1jqFy8Ca17uFWrKFs7Zr1Ykr48tw1Fvrn8XFyxXF1xKay5J3Z3GrZ5Zw13 Aa4ftrs5CayUJFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x 0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU1c4S7UUUUU== X-CM-SenderInfo: 50xn30hkdlqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xu Kuohai Some test cases does not destroy skeleton object correctly, causing ASAN to report memory leak warning. Fix it. Fixes: 0ef6740e9777 ("selftests/bpf: Add tests for kptr_ref refcounting") Fixes: 1642a3945e22 ("selftests/bpf: Add struct argument tests with fentry/fexit programs.") Signed-off-by: Xu Kuohai --- tools/testing/selftests/bpf/prog_tests/map_kptr.c | 3 ++- tools/testing/selftests/bpf/prog_tests/tracing_struct.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/map_kptr.c b/tools/testing/selftests/bpf/prog_tests/map_kptr.c index fdcea7a61491..0d66b1524208 100644 --- a/tools/testing/selftests/bpf/prog_tests/map_kptr.c +++ b/tools/testing/selftests/bpf/prog_tests/map_kptr.c @@ -105,7 +105,7 @@ static void test_map_kptr_success(bool test_run) ASSERT_OK(opts.retval, "test_map_kptr_ref2 retval"); if (test_run) - return; + goto exit; ret = bpf_map__update_elem(skel->maps.array_map, &key, sizeof(key), buf, sizeof(buf), 0); @@ -132,6 +132,7 @@ static void test_map_kptr_success(bool test_run) ret = bpf_map__delete_elem(skel->maps.lru_hash_map, &key, sizeof(key), 0); ASSERT_OK(ret, "lru_hash_map delete"); +exit: map_kptr__destroy(skel); } diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_struct.c b/tools/testing/selftests/bpf/prog_tests/tracing_struct.c index d5022b91d1e4..48dc9472e160 100644 --- a/tools/testing/selftests/bpf/prog_tests/tracing_struct.c +++ b/tools/testing/selftests/bpf/prog_tests/tracing_struct.c @@ -15,7 +15,7 @@ static void test_fentry(void) err = tracing_struct__attach(skel); if (!ASSERT_OK(err, "tracing_struct__attach")) - return; + goto destroy_skel; ASSERT_OK(trigger_module_test_read(256), "trigger_read"); @@ -54,6 +54,7 @@ static void test_fentry(void) ASSERT_EQ(skel->bss->t5_ret, 1, "t5 ret"); tracing_struct__detach(skel); +destroy_skel: tracing_struct__destroy(skel); } -- 2.30.2