Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3523894rwb; Sun, 9 Oct 2022 06:37:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM52FTFBEiTb232Gwo4E6Y8a8CtS+V/6msEBE6P3lTD6UgsKcXxshQyuVSDutA6rVYJIk4vq X-Received: by 2002:a17:902:ef89:b0:17f:8097:83bb with SMTP id iz9-20020a170902ef8900b0017f809783bbmr13646687plb.20.1665322635557; Sun, 09 Oct 2022 06:37:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665322635; cv=none; d=google.com; s=arc-20160816; b=KWikWCox/mQG+0KooIPq/31lqekLMdKnSweeWIT3j9q/4B0ooEdXdC7GTq9+Jy/A3R KSpnmCxQMduSidJXHIsi3fG/JXNfli5KXxZPn6KTZGRztyqccgomfqCpwYANG8k2qhRR 7zDCMcs2JEJ5F87VsQSh352OMr55bloylAtBgr8fW10wT3WEtrAluD4nPcupGhXFDKNA vtfdxB3lGkx+M9m8qraKhX0gcH+tGnp2XOilZGoPhG7JvdnzFhbxWB8KASqoTlhLX3E9 pGYO+z/4rzC4nyDW5XzixhxqObrehyVPmFuuQ5SJ/qE+VxQ80C+MrF5hc+OOHLgN1W1N 3oeA== 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=/Lzdvw355aEl5JGRO+aoQLcxwIdjllZ18hxGF9+zy9I=; b=SBV93G7GeBSNmN6nLEpNw87XHpdn3mMsYjIKBKmhVmBOu7LJacdF/RFQeurf6YyPoN +0sTT2zTjupT2Ut/RGT6CyT746oX1I6t6DcxjFZWaI4I657IaSFPlQm67TwBphOX0bbu Qbs6r3pp9v4/jko0cEmIHU6Ihp937gKD/GT0Dfql8QkGkhgsNnamvGdambb0XanCcycW 4QGy9PBZ2JOqQ55iXbymCddNu9GDf3/7huVPK6e4CTs2gOs7ONyDL+dXFV2cJ9GE6XsT j4H17znZ+rEeH++oPFqmMvRkQ7CEESyRtsa1KCSyNCyBc+lYz/bQs+KXaZGZP0IOKosT PW8Q== 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 j24-20020a170902759800b00178a33faa42si7900125pll.66.2022.10.09.06.37.00; Sun, 09 Oct 2022 06:37:15 -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 S230187AbiJINBN (ORCPT + 99 others); Sun, 9 Oct 2022 09:01:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbiJINA7 (ORCPT ); Sun, 9 Oct 2022 09:00:59 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDA1E25584; Sun, 9 Oct 2022 06:00:55 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Mlhv66vBDzl598; Sun, 9 Oct 2022 20:58:58 +0800 (CST) Received: from k01.huawei.com (unknown [10.67.174.197]) by APP2 (Coremail) with SMTP id Syh0CgDHX9T6xUJjwRQEAA--.16593S5; Sun, 09 Oct 2022 21:00:53 +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 , Kui-Feng Lee , Kumar Kartikeya Dwivedi Subject: [PATCH bpf-next 3/5] selftests/bpf: Fix memory leak caused by not destroying skeleton Date: Sun, 9 Oct 2022 09:18:28 -0400 Message-Id: <20221009131830.395569-4-xukuohai@huaweicloud.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221009131830.395569-1-xukuohai@huaweicloud.com> References: <20221009131830.395569-1-xukuohai@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgDHX9T6xUJjwRQEAA--.16593S5 X-Coremail-Antispam: 1UD129KBjvJXoWxGw45uw4xur47Xr13Aw18Krg_yoW5AFykpa 48Z34jkF1SqF4jqry8Aa17urWfKF4kXryYkr40qw1rZr4DXryxXF1xKay5J3Z3GFZ5Zw1f Za4Syrs3Aay8AFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBFb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMc Ij6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_ Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAI w20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x 0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x07UAkuxUUUUU= X-CM-SenderInfo: 50xn30hkdlqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE autolearn=no 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. Signed-off-by: Xu Kuohai --- tools/testing/selftests/bpf/prog_tests/bpf_iter.c | 4 +++- tools/testing/selftests/bpf/prog_tests/map_kptr.c | 3 ++- tools/testing/selftests/bpf/prog_tests/tracing_struct.c | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c index 3369c5ec3a17..6464fc021949 100644 --- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c +++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c @@ -1515,7 +1515,7 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool link = bpf_program__attach_iter(skel->progs.get_vma_offset, opts); if (!ASSERT_OK_PTR(link, "attach_iter")) - return; + goto destroy_skel; iter_fd = bpf_iter_create(bpf_link__fd(link)); if (!ASSERT_GT(iter_fd, 0, "create_iter")) @@ -1536,6 +1536,8 @@ static void test_task_vma_offset_common(struct bpf_iter_attach_opts *opts, bool exit: bpf_link__destroy(link); +destroy_skel: + bpf_iter_vma_offset__destroy(skel); } static void test_task_vma_offset(void) 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.25.1