From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by gnuweeb.org (Postfix) with ESMTPS id F38877E317 for ; Tue, 12 Jul 2022 13:30:07 +0000 (UTC) Authentication-Results: gnuweeb.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=A0HZ3XRj; dkim-atps=neutral Received: by mail-wm1-f51.google.com with SMTP id v67-20020a1cac46000000b003a1888b9d36so6777277wme.0 for ; Tue, 12 Jul 2022 06:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c/sYXMoiNTcLP4oKia5QR42veWinE4cNjWYJuUyBSyg=; b=A0HZ3XRjr20kgR1tWrM1jW4cvR2su5kDxMBHTSH67PN2hoL56wN/CnYJXUFc8GHaDu 7ASpMkJfV9Lc/ylHpcVrju+tH7J3uPDWYhRv8KrEQPbyW7dPWYouM1EhxWOtG45W/+8O CaLQm7S3ItQjOLfUts32q9xTtEOVfEPcDbk/C1sQDNOj8NzmDTlc/l5naxoqPWFUtzSc bSrp1iq/8tyaWpAv2dRwhY3xA87xtgx45LVWvAl6WrCR90C+/OQ/yAHgPj/hyOW/jjrq 0OA46fBk/pA5xaU2BhGQNcuzHmVvWVTf1VYBVjJx/vW0GQuZhGgIRXA95sp/y2A+cZaf ndRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c/sYXMoiNTcLP4oKia5QR42veWinE4cNjWYJuUyBSyg=; b=J87xMGs45FFqFkISLwbJ5RZZJgCgNFqMXUCjcAR3+OWJkMoKDOscc4Mt454vLHWB7Z nuOgloQPQc/yReiyV4+BcetjJvz81SRUvHU0a/PlSBRJmrUpUEfKcFpHBOd4dmY0b/HL DGRquoXv8edkt9Dm7/8pZn3DRluG4Z6fbr6hnV5aPFWd3qmA1oGtoVpBzogxaKjvLFWB oXVuxbJKejl1t+u2Km/qlhNl1qTrZczo2TBRTs/+z4i2qJ410L7H/J7RBlHtoKtTmEv3 7lQlGUprUarg1zctj61cdPRgSirfBB8XN+Su+l1V7tSITTCarEuRrvN3XbGd7qHnBWUJ LQfg== X-Gm-Message-State: AJIora87z2eoSt7Txz/tz7y6qMht03dUyYM5j0QmXTH3L+6BJEl3m5Ci PeitOSbhmtnsHaYq6pZxVY62jfzsMs50I275raXVjg== X-Google-Smtp-Source: AGRyM1vu7DcsXuBkpabZhgZFZXQozrTIgb+hGPIn/6EIEiTTb8/vCysY8izu1qDoJ1sCT0R8dJds1BGPr7eCu4jH/qg= X-Received: by 2002:a05:600c:4fc8:b0:3a1:99cf:800 with SMTP id o8-20020a05600c4fc800b003a199cf0800mr3853176wmq.60.1657632606217; Tue, 12 Jul 2022 06:30:06 -0700 (PDT) MIME-Version: 1.0 References: <202207101328.ASjx88yj-lkp@intel.com> In-Reply-To: <202207101328.ASjx88yj-lkp@intel.com> From: David Gow Date: Tue, 12 Jul 2022 21:29:55 +0800 Message-ID: Subject: Re: [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy' To: Dan Carpenter Cc: kbuild@lists.01.org, Daniel Latypov , kernel test robot , kbuild-all@lists.01.org, "GNU/Weeb Mailing List" , Linux Kernel Mailing List , Shuah Khan , Brendan Higgins Content-Type: text/plain; charset="UTF-8" List-Id: On Tue, Jul 12, 2022 at 8:51 PM Dan Carpenter wrote: > > tree: https://github.com/ammarfaizi2/linux-block shuah/linux-kselftest/kunit > head: 7635778bac7e46458392c1261e3916e8e9e86860 > commit: d2fbdde838f270377de4fc20e919aac3941ea55f [4/16] kunit: use kmemdup in kunit_filter_tests(), take suite as const > config: arc-randconfig-m031-20220707 (https://download.01.org/0day-ci/archive/20220710/202207101328.ASjx88yj-lkp@intel.com/config) > compiler: arc-elf-gcc (GCC) 11.3.0 > > If you fix the issue, kindly add following tag where applicable > Reported-by: kernel test robot > Reported-by: Dan Carpenter > > smatch warnings: > lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy' > > vim +/copy +78 lib/kunit/executor.c Thanks: clang-analyzer also picked this up here: https://lore.kernel.org/all/c8073b8e-7b9e-0830-4177-87c12f16349c@intel.com/ (... snip ...) > a127b154a8f2317 Daniel Latypov 2021-09-14 76 filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL); > a02353f491622e4 Daniel Latypov 2022-05-11 77 if (!filtered) > a02353f491622e4 Daniel Latypov 2022-05-11 @78 return ERR_PTR(-ENOMEM); > > kfree(copy)? Is the burden of random devs looking at this warning > forever more than the burden of adding a kfree()? Hard to measure. > I mean, it's the burden of not only adding a kfree(), but also a couple of {}s. :-) Regardless, this patch should add them: https://lore.kernel.org/linux-kselftest/20220712095627.1770312-1-davidgow@google.com/ > a127b154a8f2317 Daniel Latypov 2021-09-14 79 > a127b154a8f2317 Daniel Latypov 2021-09-14 80 n = 0; > a127b154a8f2317 Daniel Latypov 2021-09-14 81 kunit_suite_for_each_test_case(suite, test_case) { > a127b154a8f2317 Daniel Latypov 2021-09-14 82 if (!test_glob || glob_match(test_glob, test_case->name)) > a127b154a8f2317 Daniel Latypov 2021-09-14 83 filtered[n++] = *test_case; > a127b154a8f2317 Daniel Latypov 2021-09-14 84 } > a127b154a8f2317 Daniel Latypov 2021-09-14 85 > a127b154a8f2317 Daniel Latypov 2021-09-14 86 copy->test_cases = filtered; > a127b154a8f2317 Daniel Latypov 2021-09-14 87 return copy; > a127b154a8f2317 Daniel Latypov 2021-09-14 88 } > Cheers, -- David