Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7479690ybp; Wed, 16 Oct 2019 09:15:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYViG2vxy3ENe4QfMmCwrJrLUWEcLWQ6nlSe1x79nk29XK1c4BuJceoyKA3dxq+RA5Baez X-Received: by 2002:a50:d4d7:: with SMTP id e23mr40116840edj.135.1571242508288; Wed, 16 Oct 2019 09:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571242508; cv=none; d=google.com; s=arc-20160816; b=HssFRX84ite1DtpDdgK5l+Fgiehw5Mw25H1Rb0YH5yWasoMMiWz9BH6af/+AzILgP2 cjziC59owPd83Y1uToMmZZsiD8fyFwuMBGEjLTvDZL41eXyh95d4RhbMcZ9+++P8DqQp qac/NNZ8JRJBCTYvwzAB0LusnTRtfhcTyzv4UaUNAOmhKNrauXsCM3ZsRWg7IO+k3onM Ibe6M77v7OHxNYMULZFB0ug64gqJcx5ZMcfusBRn3EL+Z3vs6r6dXmKVDlau3fm5dQ6C oiG+NdHyv3LmoJqkKFnhDUOLZgcbB5v+1CnCcT70ri5jahLPLwuVB0WLpZ82vCiPamsX 5f3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=jN7Dveffqa87qcgYwBlcVqa13+mGccK4fLl9wVw4FPc=; b=rolcEPgaBaeSf7soP/G0CkbZTErP5dk1/QAncbCnkw126SNmEnYKLNmA1YtLj2vQ0u 4xVxvGoqROXAHb7/36VqIKENWVS4Xt3qcIl74OoAM9pfLpv1fqBZU3/B8lvtwROZ7S7x i6omZPEJd8geW3kClzOkxqY3eyfe8MO1Nim+iM7KiUUX3nCsUfTNzdfb2kwEJUCfIMb/ XYtP2rVLqJeSme2Cvs+dkDeti3l1OlMhxWCJwSrJTfOuO+5OPQ4VFzSv7s2Ddna8qJux S58FkDUZq0xDI49XVziED1hvTqVRq5NGiFb444WJbkcfOv2snGiksF0E5UCbYULIlmNL 7Zug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qh7WLKvM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i19si15926048ejf.247.2019.10.16.09.14.45; Wed, 16 Oct 2019 09:15:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qh7WLKvM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393816AbfJPOJB (ORCPT + 99 others); Wed, 16 Oct 2019 10:09:01 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:46347 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2393799AbfJPOJA (ORCPT ); Wed, 16 Oct 2019 10:09:00 -0400 Received: by mail-qk1-f195.google.com with SMTP id e66so2288038qkf.13 for ; Wed, 16 Oct 2019 07:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jN7Dveffqa87qcgYwBlcVqa13+mGccK4fLl9wVw4FPc=; b=qh7WLKvMAOxf6aSAkLv9y3u3GnZy1KBJyQu9ajT5VYiT9VKe8KjPVW4ZUU6CrPrOCA x+QOoWuBn3ELp3AbKuVCyoSXfbWgovYjyPXv2TjvvM4fQy4lloJ4nI5yIIkRnnJ60vO2 NL6e24sFZJc4oycdYMq5gT22urPN3kd7QfkGNJVfmNTBTy58NbUfhR4YQN7GgebpjZNx P0bNv0j8gAt3Xeuciy3RyMIwqbKWe3Fv9axfjpsmKh0eP7/JpfmH+DLlXrwAHcRX/s3r DCuLeBF5hm13J1CkDc+hlqiIryGZtxoetqGX7mS0QP7b5sISdj/W+DN5Balhme4u+fNs IBdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jN7Dveffqa87qcgYwBlcVqa13+mGccK4fLl9wVw4FPc=; b=g8y5UnOmRgn4LhHpaBe/7Apxc2IE4cChLpfAmdC5L2Rp49orn0fuxrKGCIe3IgBSH9 YRLU+91l3896pglysFzi7aW1CGIva8OSTKGcdSESVtitSvNRPE50lMkrtbeKvm9pQJ08 05AVkMNtD5+m1C3k/E69t3k87pWBjldi/RlH3hmQA3XFTkE5/IOMQpa4Y3D8OmfZkiVb Tr/NDvl8dlG6uO4kmXLBLUGgIQRjqtMcEunIX07OS8+n8rlmVz+NqDD4BiF4efi79EOp qvp2WUmgLRtMGed7LN1ro/TTZKGLOQavYvnfPVZm9Q30CTAyRcJFpRw5T5eAwZ6ze5GF ToxA== X-Gm-Message-State: APjAAAUNrNZzSAlWxrtfEAV7Ht2ZLuJYMnyGl0RTBtqXkSrf9R7NNu9i Y3DUVXKa8ibku7aQYwU1QbY= X-Received: by 2002:a05:620a:215b:: with SMTP id m27mr3755302qkm.328.1571234939220; Wed, 16 Oct 2019 07:08:59 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.50]) by smtp.gmail.com with ESMTPSA id c12sm10494913qkc.81.2019.10.16.07.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Oct 2019 07:08:58 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id DBC924DD66; Wed, 16 Oct 2019 11:08:56 -0300 (-03) Date: Wed, 16 Oct 2019 11:08:56 -0300 To: Yunfeng Ye Cc: Arnaldo Carvalho de Melo , peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux-kernel@vger.kernel.org, hushiyuan@huawei.com, linfeilong@huawei.com Subject: Re: [PATCH] perf kmem: Fix memory leak in compact_gfp_flags() Message-ID: <20191016140856.GG22835@kernel.org> References: <20191016130403.GA22835@kernel.org> <20191016130921.GC22835@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Oct 16, 2019 at 09:19:54PM +0800, Yunfeng Ye escreveu: > > > On 2019/10/16 21:09, Arnaldo Carvalho de Melo wrote: > > Em Wed, Oct 16, 2019 at 10:04:03AM -0300, Arnaldo Carvalho de Melo escreveu: > >> Em Wed, Oct 16, 2019 at 04:38:45PM +0800, Yunfeng Ye escreveu: > >>> The memory @orig_flags is allocated by strdup(), it is freed on the > >>> normal path, but leak to free on the error path. > >> > >> Are you using some tool to find out these problems? Or is it just visual > >> inspection? > > > By a static code anaylsis tool which not an open source tool. thanks. Ok, so please state that next time, just for the fullest possible disclosure and for people to realize to what extent problems in the kernel and in tooling hosted in the kernel is being fixed by such tools. I.e. you don't need to release the tool, not even give out its name, just something like: "Found by internal static analysis tool." Thanks, - Arnaldo > > Anyway, applied after adding this to the commit log message: > > > > Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string") > > > ok, thanks. > > > - Arnaldo > > > >> - Arnaldo > >> > >>> Fix this by adding free(orig_flags) on the error path. > >>> > >>> Signed-off-by: Yunfeng Ye > >>> --- > >>> tools/perf/builtin-kmem.c | 1 + > >>> 1 file changed, 1 insertion(+) > >>> > >>> diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c > >>> index 1e61e353f579..9661671cc26e 100644 > >>> --- a/tools/perf/builtin-kmem.c > >>> +++ b/tools/perf/builtin-kmem.c > >>> @@ -691,6 +691,7 @@ static char *compact_gfp_flags(char *gfp_flags) > >>> new = realloc(new_flags, len + strlen(cpt) + 2); > >>> if (new == NULL) { > >>> free(new_flags); > >>> + free(orig_flags); > >>> return NULL; > >>> } > >>> > >>> -- > >>> 2.7.4.3 > >> > >> -- > >> > >> - Arnaldo > > -- - Arnaldo