Received: by 10.213.65.68 with SMTP id h4csp2156531imn; Sun, 8 Apr 2018 21:10:14 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Hb722vvmy7IJjDvQAMtQ0ofV0Zer6SMSmT7A7Iihd/KN3c1qjnYToZkHf07OyRc4r+MXo X-Received: by 10.99.146.83 with SMTP id s19mr2901635pgn.104.1523247014125; Sun, 08 Apr 2018 21:10:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523247014; cv=none; d=google.com; s=arc-20160816; b=GTmdCzoEiu7a6kK1hlH8OWl0s3iC1vfvudnMag7LJiwd8eqvPWZANA1rSkLnnv5Vq3 bOLnaFjmikSpNPi1+/3ldY+wjlzrNMVaEwpKranf2qWDvjdPQBmeQz+zP9tFyfl1GkBd tO0+CV/qRIxIaqUd3IRtK4bca8CvcJXUlZAAaWRuvd60zt4s+7ifeAC0pvHxhz1r3ZLP xM5r3+sW1zDbb3NhJfhEs+DEDIVOkO59Ag8Lf3tHueixNXtOuIhtZUkI+3jCU+HY6INa WMtf9izp8HcyD32PMr9uOf+RhKBycMXQnZFIkFqgAnyP8BJG6kxl8AhWotVRj3474h8k 8Zow== 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=eYC+tcftct65xJ9KPvm6CjrzBzRAPwnFjY5ULLvDlSE=; b=KsTeA/KiKqDIuvHCfWzYvnZe1Zw2ZyPqosji8Nru+CdpLxKe7YrmtWVevoL3DnAb6l KSyPuaNwgTSaqFnrCRoNp7ubHyjT4R85m3GV3XfpyWXY+SUxGW3QZ9LperejNLh+zvPo kTqYzbYuIba7Md27xpLsDAIHFQ/0QHPE7y+B3XzkzqF/7NYoqdjhgL6LznEqBOcFFWav BUP/wM1NAlb6a+FlJmG764Ey/2qS6NQ+Ck81Apq8FmWbH3i679axmZprGIgvudquHHJ6 AYWqlSYB4wVbSEwFnO3Kl6ZiBV1uTBwoWUOMxgeG99znFGdHzgXRem72ZgZpe7z2UTjk 7mNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Kv9jbr3l; 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 c12-v6si12980878pll.498.2018.04.08.21.09.36; Sun, 08 Apr 2018 21:10:14 -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=Kv9jbr3l; 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 S1754029AbeDIEBs (ORCPT + 99 others); Mon, 9 Apr 2018 00:01:48 -0400 Received: from mail-co1nam03on0092.outbound.protection.outlook.com ([104.47.40.92]:42112 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753397AbeDIASH (ORCPT ); Sun, 8 Apr 2018 20:18: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=eYC+tcftct65xJ9KPvm6CjrzBzRAPwnFjY5ULLvDlSE=; b=Kv9jbr3ll4mwau2c5+90xeTgcmZsyYRv2sm29+TtupWVRAz4R5sv72zTVopzOaqj003EuizdfegCJuMq+E54VM23prKvrlxRNdgunIUqgIxCXK2+QYOVnRk0lWt/PgsHp1wBbnWJ0uD+vDeycFlu1eJojUbwgQFOA9eR3Mvc4tA= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1046.namprd21.prod.outlook.com (52.132.128.15) 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:17:54 +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:17:54 +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.15 054/189] kconfig: Don't leak main menus during parsing Thread-Topic: [PATCH AUTOSEL for 4.15 054/189] kconfig: Don't leak main menus during parsing Thread-Index: AQHTz5gkXXmeZHHwyU2kzNmbCO9fyQ== Date: Mon, 9 Apr 2018 00:17:28 +0000 Message-ID: <20180409001637.162453-54-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB1046;7:SxxNf29l1Xr1ImIM/L40VSVYbrF2EwQTFHOC1phzc79ysSpIpHiDzQVwDzbIKWCM6DM2lHyVQMmfgSY0Bx7nbk8Ve3SaYJ9qv2ts8HL+ciz8Y32GwYZTw6WzMXs05fxPCAlhC8D/abhBKwTyXrMRZW3zJ+ZhNNptR2RTecRgrs8CTrEpI8O9YT58jytUkoBJa5Mebui7IoDlQqkE2hAITCtbYDA9XPRMZ9eG2iCtu6OanuZIYGkKW6REjnxBfhKi;20:g3HIFX1McGaVuyiwwiTQUKD3NDOjxldymYvSSQ76UjBywl9gm8JeQ8rdER+aYjTmY9SCBFj/4hpRkvdZUuqb1m3u0hcdJHOjUWRlyf2i22qn+U5ZvDrLcIFLmUVoHNm68GorY985l6kZnCrjFdhkoYOggN9UAJ/N2JX+6gFtNn4= X-MS-Office365-Filtering-Correlation-Id: 4ba8e45b-2a89-490a-e750-08d59daf56b3 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB1046; x-ms-traffictypediagnostic: DM5PR2101MB1046: 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)(3231221)(944501327)(52105095)(10201501046)(3002001)(93006095)(93001095)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1046;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1046; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(346002)(376002)(396003)(366004)(39860400002)(199004)(189003)(36756003)(186003)(11346002)(446003)(476003)(2616005)(7736002)(5660300001)(26005)(10290500003)(478600001)(106356001)(6666003)(68736007)(10090500001)(54906003)(3846002)(59450400001)(22452003)(6116002)(86612001)(110136005)(99286004)(86362001)(72206003)(305945005)(76176011)(102836004)(6506007)(486006)(316002)(3280700002)(3660700001)(81166006)(81156014)(8676002)(2906002)(14454004)(2900100001)(97736004)(6486002)(8936002)(1076002)(6512007)(6436002)(105586002)(39060400002)(25786009)(4326008)(2501003)(5250100002)(53936002)(66066001)(107886003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1046;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: nNr2pPPUGYNVPZpoRz/PYypy1qU0ruIBikGPbgFq16joWixc3XQpHZY/7169XVdcR8qKCzsc6GHWsP3d+ZrPro5m/1EQxSnHtVxCJj5sARb3OlnIg7CaxnYaLVL42rWVfsLF+UGpk9ccKTSvf7Ee8q4i598pUcEJgVWrubBJMXKrIXW5Yy8wKgNPFZuwcQPluJKbVEbxs1BBtp1LyKP5EnaBlON1qQipoT6/lGUt78XR07PYeXXU86I9Un1xKrRlOR3EOMKWEkWT/fUHtY/lQDzaXTnDWJOfOKfkKBj5raIWcN1QrOCRpWkMYwYR0rzV4l4TDu1m/Yool2q/JSx//WclofjpZl3/No5T7BDtSezOKo5OWaVc2Dz1XQTDA/oRB3P867u7bbnfftqhU4Y45vMAfYQ47TfJTyCQea2idDE= 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: 4ba8e45b-2a89-490a-e750-08d59daf56b3 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:17:28.5565 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1046 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 c8f396c3b190..20d9caa4be99 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -108,7 +108,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 */ @@ -351,13 +371,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 @@ -502,6 +515,7 @@ word_opt: /* empty */ { $$ =3D NULL; } =20 void conf_parse(const char *name) { + const char *tmp; struct symbol *sym; int i; =20 @@ -509,7 +523,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; @@ -519,8 +532,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