Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7466067ybp; Wed, 16 Oct 2019 09:04:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDroTP4nlfmFgetQQ7HcrnCy+/GuBFOu8bJt3gXXngqKKmpKEEMCsUpDEJ+lTbvRPeMNdK X-Received: by 2002:aa7:c603:: with SMTP id h3mr40120247edq.44.1571241863486; Wed, 16 Oct 2019 09:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571241863; cv=none; d=google.com; s=arc-20160816; b=fEWVom82Y/454Mqwepb1S1kugm2x7DrkZG2+oONO5VTRmekT1tBdS1uBllRcnFcvjO iaBFJWt/ig9Zbm56+Zf+pwC+NopHt8QRN7jrCSWXGMyiZ3Ane5iOKabIB/VLOV3cpwEW bunbvW7ruwSR2ztJds2iH1KrO+QKjpEy1FPfOuekSTC/hvYxP4RKUwEEI+lzkOKsL7jR oKuvldL09JYMYSphV2OJ+ZEg/tLmwhwpDBC5mK8DM4hGNdHcUY4fhUPW093Biau4Ho50 ovXAT5mDv9CXcWXWJG7mjLMrsI4Qaa7I3mgYcw2mrx68UwnTpGuJJB0HXZWgdfejYRg8 KLgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to; bh=2hG62C1hVJHkYMrg53gZvdB8ecX3X19A11X7HG4i3OE=; b=oDklwkj1/UqZ/9XwbbbH7E0L2rVB6iMV2UCqzbjd9Kh4Ya2EcCAWFpO2k57WtBn+wE RR0ocvitkNU9n/1hmeaXdLlGd2/jpu/+L6AbJemRz+FN89KZnTxVBJT7mkLzkAVcu02/ 5KcNZIdLdQki1XQh7pvbL9v65EIzIQ3XVfBr6xgG0ZmTf7IHazObphpRjc4bLFSgcS7d NQ/E0HO8L3oWR2S/MQIhPhTMJiWJFR8P2lPbxki4uQ29t9DDD1P3+uYx3x0NwX3cZmyW XrrJ6z1dAjSA0J2kge8ZA++bOpcLJVoPo7di83GbWZ90BGSRrwSUQOsj8vDdKP5UIu3j 83ew== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g38si17916989edg.127.2019.10.16.09.03.58; Wed, 16 Oct 2019 09:04:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405320AbfJPN1G (ORCPT + 99 others); Wed, 16 Oct 2019 09:27:06 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:58460 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2405306AbfJPN1G (ORCPT ); Wed, 16 Oct 2019 09:27:06 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 97D91C3D7BF18CD95467; Wed, 16 Oct 2019 21:27:03 +0800 (CST) Received: from [127.0.0.1] (10.177.251.225) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.439.0; Wed, 16 Oct 2019 21:26:54 +0800 To: , , , , , , CC: "linux-kernel@vger.kernel.org" , , From: Yunfeng Ye Subject: [PATCH v2] perf kmem: Fix memory leak in compact_gfp_flags() Message-ID: <7fd48f77-fbc4-b99f-60c1-ccc7d8d287e9@huawei.com> Date: Wed, 16 Oct 2019 21:26:50 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.251.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The memory @orig_flags is allocated by strdup(), it is freed on the normal path, but leak to free on the error path. Fix this by adding free(orig_flags) on the error path. Fixes: 0e11115644b3 ("perf kmem: Print gfp flags in human readable string") Signed-off-by: Yunfeng Ye --- v1 -> v2: - add "Fixes:" message 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