Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp326195pxb; Thu, 19 Nov 2020 02:07:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2WnbwCneUriX4gDD+mxL6UDs6AJnaCPzTBy0OZo3xLmLV+ym/GXKrzklqna2WoPynx4Yd X-Received: by 2002:a17:906:2481:: with SMTP id e1mr28840409ejb.235.1605780452530; Thu, 19 Nov 2020 02:07:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605780452; cv=none; d=google.com; s=arc-20160816; b=LVwLpQhR+TzQ+MCq13pSGaeSQ1VliY4e89zO+RylCzEq04ssOaNGyFj6ABdJK0NZbR Cc433faXh6qv/2mHA4mnJY5JMyMH6Y4kBoZQHbL8Iu32VBK5fTTxDnnP462MMmG0sfDk YNpkCsPIQUbRipAkv2nwj+PqCYH9JHX4gEI+/u4UR4KbqiyHewTBHr32EPqJ00GFtBdN +DdfJj3ut0Ph6viZL+ocbajlry/CI6Lj7GB4BVvJUbkD6aBst+nUMR9/F3w4JKYKwKNn cqThpVQlpBu2ughXaWIvizGKORBfvKwQYAJ2FUoXZqMcDNC5Il+5Lg52gp/iVexkRQK7 7edA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=tiPYZ+RvISPedINFWyyuwuepRwvG2w0UkGSwoHhILaY=; b=qi+96jhpD5zFPP/pY7u1pqw58mmiUy5k8LBzSshlrZRzw6bLEh0T/FeaMaesOD8cvp /PpRJq7a5OSi7kblXG2kxS6lkMbeum0ERFg1neVBWsaBxHGy1eYr16ekPciYY01NDGn7 8UaDGGKIPU9Ikr71CpjXSU+CxzT3Ejydta+PDtN+R+bQ5iU2cDZNxbFsStasU3Qw5glJ fxAa5u5kfpIX6wbiap/9+gIUh+xX45Ygq9WMTFxkKKap7zhgSuWD7M/EFu9D3GKoWVru zaPcw4kLaaidMv9VZEpJG28jk47T/+CACQzkkTgNA+jDHNttyvVbcYRtpjGxFb1YgzNc GsAA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f21si16414400ejk.90.2020.11.19.02.07.06; Thu, 19 Nov 2020 02:07:32 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727127AbgKSKEg (ORCPT + 99 others); Thu, 19 Nov 2020 05:04:36 -0500 Received: from foss.arm.com ([217.140.110.172]:51884 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbgKSKEf (ORCPT ); Thu, 19 Nov 2020 05:04:35 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CB4FD1396; Thu, 19 Nov 2020 02:04:34 -0800 (PST) Received: from e121166-lin.cambridge.arm.com (e121166-lin.cambridge.arm.com [10.1.196.255]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E3AF13F718; Thu, 19 Nov 2020 02:04:33 -0800 (PST) Date: Thu, 19 Nov 2020 10:04:28 +0000 From: Lorenzo Pieralisi To: Peng Fan Cc: Kishon Vijay Abraham I , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Xuefeng Li , Tiezhu Yang Subject: Re: [PATCH] tools: PCI: Fix memory leak in run_test Message-ID: <20201119100428.GA14090@e121166-lin.cambridge.arm.com> References: <1591875166-12243-1-git-send-email-fanpeng@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1591875166-12243-1-git-send-email-fanpeng@loongson.cn> User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 11, 2020 at 07:32:46PM +0800, Peng Fan wrote: > We should free "test" before the return of run_test. > > Signed-off-by: Peng Fan > --- > tools/pci/pcitest.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tools/pci/pcitest.c b/tools/pci/pcitest.c > index 0a1344c..7c20332 100644 > --- a/tools/pci/pcitest.c > +++ b/tools/pci/pcitest.c > @@ -47,6 +47,7 @@ static int run_test(struct pci_test *test) > fd = open(test->device, O_RDWR); > if (fd < 0) { > perror("can't open PCI Endpoint Test device"); > + free(test); > return -ENODEV; > } > > @@ -151,6 +152,7 @@ static int run_test(struct pci_test *test) > > fflush(stdout); > close(fd); > + free(test); > return (ret < 0) ? ret : 1 - ret; /* return 0 if test succeeded */ > } > > -- > 2.1.0 This is not necessary, though good practice but I would do it when run_test() returns not as you did. Patch dropped, feel free to resend it. Lorenzo