Received: by 10.213.65.68 with SMTP id h4csp2114295imn; Sun, 8 Apr 2018 20:04:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx48jwTnZNiymY+L+IV5QPPASmGcqgaQ5QCHbHyusWph1xrhtc316zAgus973D7Pt7C2KWolG X-Received: by 10.98.156.91 with SMTP id f88mr12847428pfe.128.1523243070490; Sun, 08 Apr 2018 20:04:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243070; cv=none; d=google.com; s=arc-20160816; b=JtCpgi993ZQWJTmbDvA/3NffxmFd17OMAiuQ8khNxAkdHjLXaFi9sZu9ZswUXX1M4B 2CWXRididZh+MP+Ov2ZoLYaAkDxZ+gT5tz4E3bV1EZpIQCwKRu3FTmyngFeWzyYvfhmQ xXSY9+7ClR00MhoHxDlJMWIMRXvBW+u+defDhQe7IdCtV+mJgwuSeUZLfdv+CL3KTGcK M5NQzYFO1JrHI2DivaIoUEmyPb1deeBskphwhXj+qNQPQPYQHKh3WY6QqvlXP1bN8y0Q dA0/HVFqesLwn3ISkYl+VpsuHdklTfOBVGVeUQWztLgj2bwXIM4IIIBN/Faq2oW7VHDx SSWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=xGUUxqJKGpq3k+FUKvlOFQM9Ljfl+xyqerXYD4bhT2o=; b=zFh+Eo4ECFrKFPE5po1StaEXmcVcrkD9vo0nhI6UPh9LveUc+qwae81cms7rssihAF nFobL3QujfGIN6IyAUXW3KljApJEOfU/TJTMaAc8ZbzpbliG7k0kskcJTrNQxr09oB/z UyMEqJypV3UELrvKt0RtympYdVCaMw/ZQPGgMmq463+qcVBnoODFRjxsmZwAaqSfeNkj +ylpz33MOv8Hyqxb/G2JhnyDeM6Hn+elcUuVfTydXsmFGqjrdadzzUneSJ6gaspKU8/A MwE8gjw7L6w5htPPD4qRz/oOoIox/+IRzQE9REjfhYzNw3uKzRICV1wFtdg7uP6/GjY7 YPaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=VWSxqroG; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r18si12109956pfe.168.2018.04.08.20.03.53; Sun, 08 Apr 2018 20:04:30 -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=@microsoft.com header.s=selector1 header.b=VWSxqroG; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932259AbeDIAeI (ORCPT + 99 others); Sun, 8 Apr 2018 20:34:08 -0400 Received: from mail-sn1nam01on0094.outbound.protection.outlook.com ([104.47.32.94]:49836 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932242AbeDIAdH (ORCPT ); Sun, 8 Apr 2018 20:33:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=xGUUxqJKGpq3k+FUKvlOFQM9Ljfl+xyqerXYD4bhT2o=; b=VWSxqroGlpJnEO83IM78OG1gFVsVe2KpXZYkPc28ENM56vMI4fr3ynfiMquQ6Fun2C/hwVVwCQk27Pxm+efH36UnRsIt/ucwtTlwDa6stkfinzgBudwmjbZX38YrfbijgHf/cmpZXuitrxIgxsONS116eCLgATYqz/EMJklEhM4= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0902.namprd21.prod.outlook.com (52.132.132.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:33:05 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:33:05 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Ulf Magnusson , Masahiro Yamada , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 232/293] kconfig: Don't leak main menus during parsing Thread-Topic: [PATCH AUTOSEL for 4.9 232/293] kconfig: Don't leak main menus during parsing Thread-Index: AQHTz5lSoiTSnGggg0CmRfIGzPXa4Q== Date: Mon, 9 Apr 2018 00:25:54 +0000 Message-ID: <20180409002239.163177-232-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0902;7:T4YFrR1wn4wu+5+ClPop1qiie0ZRhWDKIFVwPeHZlJlDTqzNoc0S9R7ti9TlfxqDprivAK+iHIdg2PH8ExyYBMlYt/fSRpP64bbVsD61P+YRLeaQgiQsBfi+sobhCCC62gKmxMBcWzEwJtsYtouNOTyL2bXDWT6J5/EtVlQ8TVD6kYgr5IDGqu3s5oqcrO5TQxgvb1ikdY0HqHv8zM2Lerdnem1cku5BGoQeaCcJdCXGXEV+JTA2EdODNsSk7aCf;20:LiQ0M0L7pGpC18Vv1Cn1mreWXfaOjWMx5hcysUfq00R1Bt9LwPI8qWlTTOgX9/aLMXfKzJt9oPadT1fPXjlYOq2FFlyUdDq85Fv7D8iF/vtwwxR94eXfme/yXAD552ghfrJ5wD69e+P4MBBLmRYGZEOwTAwZQ0AnlW6DXAjaKoY= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 6d2bd57f-2922-4aa1-e788-08d59db175d4 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0902; x-ms-traffictypediagnostic: DM5PR2101MB0902: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(85827821059158); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0902;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0902; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(366004)(376002)(396003)(39860400002)(39380400002)(346002)(199004)(189003)(5660300001)(478600001)(86612001)(3846002)(6116002)(106356001)(25786009)(6486002)(72206003)(10290500003)(8936002)(6436002)(76176011)(2616005)(6506007)(2900100001)(97736004)(26005)(486006)(10090500001)(36756003)(81166006)(8676002)(81156014)(59450400001)(102836004)(2906002)(99286004)(11346002)(476003)(3660700001)(66066001)(6512007)(86362001)(53936002)(105586002)(186003)(5250100002)(14454004)(22452003)(6666003)(2501003)(446003)(7736002)(39060400002)(316002)(1076002)(110136005)(3280700002)(68736007)(54906003)(107886003)(4326008)(305945005)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0902;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: SaFd+aLRUoFoY7G4OwMrgm3YkSXnvY0YvQDj2+/uEq8H473nBL23ZYKZmEuzPlpyXhwCML/OjRNLwICdQvunf3FJFfIsOZZROReT+cwT2IcVVSBdP+DhRej0F+c0K74AZhqUG6Y14C1XPlm6WZsHX5o8vmW7K4gKvoiUrqRzkvq22qAtWVXde3lSyajKO22SMFOiK+A9NU35I6L3etG7GxQuprRWoSJH/G6117N0/Cxdx6Ygu4Do0ZpHaCBYJuIhGovBui31VyUKRP033abrS4/tRolbHk+56v+k5HCbZUCtI3CB7NTov/PmUr8jHov5UsA0+fn8tqrvm61TFziNnmKTJdU0Kmo0/pu5pK2PXeJ4gV263R4/NDj3rg900jNqsim+3DAQVUmtmF1oCoeZscP2seFz08QxjSso77TyQiA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d2bd57f-2922-4aa1-e788-08d59db175d4 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:25:54.7848 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0902 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ulf Magnusson [ Upstream commit 0724a7c32a54e3e50d28e19e30c59014f61d4e2c ] If a 'mainmenu' entry appeared in the Kconfig files, two things would leak: - The 'struct property' allocated for the default "Linux Kernel Configuration" prompt. - The string for the T_WORD/T_WORD_QUOTE prompt after the T_MAINMENU token, allocated on the heap in zconf.l. To fix it, introduce a new 'no_mainmenu_stmt' nonterminal that matches if there's no 'mainmenu' and adds the default prompt. That means the prompt only gets allocated once regardless of whether there's a 'mainmenu' statement or not, and managing it becomes simple. Summary from Valgrind on 'menuconfig' (ARCH=3Dx86) before the fix: LEAK SUMMARY: definitely lost: 344,568 bytes in 14,352 blocks ... Summary after the fix: LEAK SUMMARY: definitely lost: 344,440 bytes in 14,350 blocks ... Signed-off-by: Ulf Magnusson Signed-off-by: Masahiro Yamada Signed-off-by: Sasha Levin --- scripts/kconfig/zconf.y | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 71bf8bff696a..5122ed2d839a 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -107,7 +107,27 @@ static struct menu *current_menu, *current_entry; %% input: nl start | start; =20 -start: mainmenu_stmt stmt_list | stmt_list; +start: mainmenu_stmt stmt_list | no_mainmenu_stmt stmt_list; + +/* mainmenu entry */ + +mainmenu_stmt: T_MAINMENU prompt nl +{ + menu_add_prompt(P_MENU, $2, NULL); +}; + +/* Default main menu, if there's no mainmenu entry */ + +no_mainmenu_stmt: /* empty */ +{ + /* + * Hack: Keep the main menu title on the heap so we can safely free it + * later regardless of whether it comes from the 'prompt' in + * mainmenu_stmt or here + */ + menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL); +}; + =20 stmt_list: /* empty */ @@ -344,13 +364,6 @@ if_block: | if_block choice_stmt ; =20 -/* mainmenu entry */ - -mainmenu_stmt: T_MAINMENU prompt nl -{ - menu_add_prompt(P_MENU, $2, NULL); -}; - /* menu entry */ =20 menu: T_MENU prompt T_EOL @@ -495,6 +508,7 @@ word_opt: /* empty */ { $$ =3D NULL; } =20 void conf_parse(const char *name) { + const char *tmp; struct symbol *sym; int i; =20 @@ -502,7 +516,6 @@ void conf_parse(const char *name) =20 sym_init(); _menu_init(); - rootmenu.prompt =3D menu_add_prompt(P_MENU, "Linux Kernel Configuration",= NULL); =20 if (getenv("ZCONF_DEBUG")) zconfdebug =3D 1; @@ -512,8 +525,10 @@ void conf_parse(const char *name) if (!modules_sym) modules_sym =3D sym_find( "n" ); =20 + tmp =3D rootmenu.prompt->text; rootmenu.prompt->text =3D _(rootmenu.prompt->text); rootmenu.prompt->text =3D sym_expand_string_value(rootmenu.prompt->text); + free((char*)tmp); =20 menu_finalize(&rootmenu); for_all_symbols(i, sym) { --=20 2.15.1