Received: by 10.213.65.68 with SMTP id h4csp2127037imn; Sun, 8 Apr 2018 20:23:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/fRhtSMuhgNmq4GP5p2/n5ZITIvxxD2L7IKND3nKwaIRg1kXCCqMDMu505rCK3mnkzkVwk X-Received: by 2002:a17:902:32a2:: with SMTP id z31-v6mr37935646plb.41.1523244231967; Sun, 08 Apr 2018 20:23:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523244231; cv=none; d=google.com; s=arc-20160816; b=yNdGZYWTNlmPOznhCfQLoMynSQegjmkn9J37CVGPeIBLEJsGnkyaiOlvNs+/3YIqHO r2izitoXS7hwgBDPVwvXs3rAvORvIgZ5DrP0wStB8n2S5AbduKECIlXnZrp/LwDf3EzI fpKb70BeWFH5lyR9IQUbHm24d19HV0nL1mePWm7xsFNUZvIQiNh0lVOU+DTafLq4aAWB QQCGF7IACWl+BIqmTHZ6e6PujFtkg0C/VMKC9Q8ryUlA+ea6DKUWIKJmFd7Co+ALSeGr S4uLVZk7JD5t9rorCveicyj/pd/OygdV0zyaRqtjswsUGXNuYRfLjOise0+W8WLAmhR7 V6xA== 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=rqGl0JgyE+7KlRUnzwPnmpPBhF/YYxg8kgQanpqyr7/MyITGAeSTTRjRAaM4jMHKV9 72ut4ZOB+uoh32QvA6RTrI0YPfBs+tRVYdShb9MhbswvxUuZQjdWJEeOcuGI192ipc7H YligFtTqfYUJbdbrFUGeu4ymTDz/VzPlbUD4TVsOyqdG8TNmuykmfM9WV5t9gjS1JElD HaZ92sv19Cwf+8HPHuCLwzGUx+EATdNyPbVt0kPhcEsQs1BXPnNUjVgZK+pbLqHqoreq wnGWBC9PBrc1FkVvY5WiEpJ0lz5iVRt12f6QSMM0s2K/z9kjfZfTklxUMzdYGclZ4E1L 3V7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=UrfSzlkK; 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 91-v6si13877656pld.396.2018.04.08.20.23.15; Sun, 08 Apr 2018 20:23:51 -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=UrfSzlkK; 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 S1753168AbeDIDUk (ORCPT + 99 others); Sun, 8 Apr 2018 23:20:40 -0400 Received: from mail-sn1nam01on0134.outbound.protection.outlook.com ([104.47.32.134]:37792 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754775AbeDIAW6 (ORCPT ); Sun, 8 Apr 2018 20:22:58 -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=UrfSzlkKA7tnmMMjaSjjnfXLB4b0JmeeNRFMEzvZEcGZLxUx8lBK7neWPyuobnzwk14N2OpCLd6Rs2SPoyS7koxh4MOe+tN+joYDWTmXNzITjZl5yBlhdRXs5Kkp4ELt9UtnaUk4mc1kHR9+/BBuOHvJOKZskAVj5DLx84iJiVQ= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1014.namprd21.prod.outlook.com (52.132.133.36) 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:22:55 +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:22:55 +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.14 046/161] kconfig: Don't leak main menus during parsing Thread-Topic: [PATCH AUTOSEL for 4.14 046/161] kconfig: Don't leak main menus during parsing Thread-Index: AQHTz5iMb3k3lnIpDkiWr971cw7iUw== Date: Mon, 9 Apr 2018 00:20:23 +0000 Message-ID: <20180409001936.162706-46-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-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;DM5PR2101MB1014;7:gqLXn0YDWAumUyoO8uU3gQ7DNzI2n6GAPaU+w7l2N9ftz/hiK2+RT3swIgRkiZp9W87IVFEe+IEuQK2gRib5G8LkWwMK+V4Vk7V7FnTS98nmARt3eh+63keMoomoypfmqK9B3WdnHt/rXCoVkTBwEbgEQMwid5veS+cC6LXzGK1dhGxzKxIW6VXk4wPg7qCYorvGZwA51wrNcgHhjo/Eeopkkzq6n1+Kah9NHkX9WVLCzSv16arqHA2jRZRe2npD;20:Z11mCyzG++8pHj97hadfzPSgLYgvEcMSvaYPnZqh+jQWMCZboYWwzZUm5XgIrGtBkD0G62GG1Bb2zfVyzdLkCb/RwFmvcYPwJvZUJ59kELF8P3apKBhSCLzgw/CzuAXMimYdNMPtQjBPh1gjvjNmO9QkuACi52igsNLAE1DvqrE= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: f9ace474-ef7b-42f9-a3aa-08d59db00a12 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1014; x-ms-traffictypediagnostic: DM5PR2101MB1014: 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)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1014;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1014; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(366004)(39860400002)(39380400002)(396003)(376002)(189003)(199004)(81166006)(81156014)(478600001)(6436002)(72206003)(8936002)(10290500003)(106356001)(99286004)(86362001)(2616005)(7736002)(2501003)(6666003)(446003)(39060400002)(476003)(8676002)(11346002)(105586002)(305945005)(5250100002)(6512007)(53936002)(68736007)(107886003)(66066001)(86612001)(2906002)(14454004)(186003)(22452003)(25786009)(4326008)(2900100001)(486006)(36756003)(6486002)(3660700001)(59450400001)(54906003)(26005)(3280700002)(110136005)(1076002)(10090500001)(76176011)(6506007)(97736004)(316002)(3846002)(6116002)(102836004)(5660300001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1014;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: kMQa8uxhdTrVfu8YVAGB6XTHyKLlNKzi/9wV8jN0sidXrgpAVuIZ3cvcO5mT3A+JfosY95Y277WuHqy4z65LdvJ1w4oQBAmP5XSNWvemPKec+G4kmYzZ7IIB3b0GV11qjQE0Of1kEi+Ezz/9TTm0bwG4S/xL7L2dqAk4sGLTsJ7ajx50PdDN1RyucYjFoMACud4SBlEHaOQMjHA91gU64VL1+n2Z9Ibs2gEGuVwPS65kOenOipQvN3m5iZVFHPK9i1Mvu0KtSnOVD908aYhG+u2SJdRUZcKxelWbhK+FqaUZTbtO/llR+SZ8AX/GLLGCLgHx9ahQhRsZNgY0FMm/xsTOr9gxbNbTES1rmlluaxD+rxL/UYT2mAqruwtSBahsybovEEVLn4ddp4XgnyJJIvqe7SYn5Hlh+Ja0L9q0oVo= 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: f9ace474-ef7b-42f9-a3aa-08d59db00a12 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:20:23.1913 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1014 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