Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2085606rwi; Tue, 11 Oct 2022 04:47:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6l755/BSVzaAiL+f0IXJ2rUh7qaRnboO6YDbCvy43lt1VG7xONhlIMgd7la9JkZbhd0Jk1 X-Received: by 2002:a05:6a00:1306:b0:555:6d3f:11ed with SMTP id j6-20020a056a00130600b005556d3f11edmr24487322pfu.55.1665488828227; Tue, 11 Oct 2022 04:47:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665488828; cv=none; d=google.com; s=arc-20160816; b=xGnAEMzzzR96mgNtOrC8w+kkcJahARCn/ExbJjjIQ5SRcPRtAE77GuEqaDr2WObik2 67oUmWxniFA/izyjwBKotV+4gU5dBn7sas/VnU1tSbSfXo075L9ijek+l1wDL3hYHMSd JMzMxZzy4mgYzslZoqt2ILKDIcZbAqdk1ElsOn6aKhkYqxGQgG9m7BihIdIMyN3ZmEnW b1wa18RfHyGZXiJ/s4et9BMvNVREWd9LP0Fiu3dSFcn0n10jcbQ1S75NtbK8a1RcW2la atxTyfohGhsL+m4fQOAAAACOJnfNQz08iSHY964rCdT1xSSTWOjAMxoGk/E6tQS09TLS njmw== 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=NyN9Mnbk2js1E4iaWURH3bX9M81S8RwZO6P3WXOuYRDJo3HVPn2npU4BGett8V0H1p GQZzqWu0ztCx0P/elI7qxuwgvo4csaPeyXcJOti6kuUbeKbTNfaOIYXK9Yo55JwyG57d +Qsv+GJv4JFkp+HSihEbCqBm/BSH9Nd8xTi3WCikshIoq5RVJhrH8EJ1XYO9Rq9tToA6 ahRRfiihCkAOiEgNgMJ0ALX/awO/dyCl4VMKI7nrhLAgwCYyp2bXuRe8ULaFSZ1RXbTC xuI4bVvF3qOl0XtJVkJN9LsJQ1xksWQA6l1EQDkJpjF2wysLyTBrmtwWO0v7WHJODKZk mTsw== 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 c5-20020a631c45000000b0043ca0a1f7dasi12871506pgm.674.2022.10.11.04.46.56; Tue, 11 Oct 2022 04:47:08 -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 S230017AbiJKLnq (ORCPT + 99 others); Tue, 11 Oct 2022 07:43:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229935AbiJKLne (ORCPT ); Tue, 11 Oct 2022 07:43:34 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8482895C1; Tue, 11 Oct 2022 04:43:32 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Mmv4W0nM8zKG9D; Tue, 11 Oct 2022 19:41:15 +0800 (CST) Received: from k01.huawei.com (unknown [10.67.174.197]) by APP2 (Coremail) with SMTP id Syh0CgBX8NTXVkVj5HNpAA--.32480S5; Tue, 11 Oct 2022 19:43:31 +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 , Kumar Kartikeya Dwivedi , Alan Maguire , Delyan Kratunov , Lorenzo Bianconi Subject: [PATCH bpf-next v4 3/6] selftests/bpf: Fix memory leak caused by not destroying skeleton Date: Tue, 11 Oct 2022 08:01:05 -0400 Message-Id: <20221011120108.782373-4-xukuohai@huaweicloud.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221011120108.782373-1-xukuohai@huaweicloud.com> References: <20221011120108.782373-1-xukuohai@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgBX8NTXVkVj5HNpAA--.32480S5 X-Coremail-Antispam: 1UD129KBjvJXoW7uFy3Cr4xWF4UAFWDJFy5Jwb_yoW8uw4fpa 48u34akF1SyF1jqFy8Ca17uFWrKFs7Zr1Ykr48tw1Fvrn8XFyxXF1xKay5J3Z3GrZ5Zw13 Aa4ftrs5CayUJFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBFb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV 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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE 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