From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 797FFA0524; Sun, 2 Aug 2020 01:34:23 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B8C121AFF; Sun, 2 Aug 2020 01:34:22 +0200 (CEST) Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00079.outbound.protection.outlook.com [40.107.0.79]) by dpdk.org (Postfix) with ESMTP id D6148255 for ; Sun, 2 Aug 2020 01:34:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E+xSoZO9uMygQexSpH2gQajncEFzOkifg+xJRKz3cEg=; b=gFDZK9eCPElw0PF1Pjw3kd6XzXN/2TonhCUV+FQAO44j8rS+5QLCwmECAFA5vBhwK3ELl3ACY0A5xLcRpQnL4ExTzFfoEAaWbbSfUFotY3KQoyJl7vCnquxPsw1nBYFF8ASpljMLQj3P4K+p1AD9gmmhXd1UF8f6igqNESyNnZc= Received: from DB6PR0501CA0038.eurprd05.prod.outlook.com (2603:10a6:4:67::24) by VI1PR0801MB1792.eurprd08.prod.outlook.com (2603:10a6:800:50::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17; Sat, 1 Aug 2020 23:34:18 +0000 Received: from DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:4:67:cafe::ef) by DB6PR0501CA0038.outlook.office365.com (2603:10a6:4:67::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Sat, 1 Aug 2020 23:34:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dpdk.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dpdk.org; dmarc=bestguesspass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DB5EUR03FT021.mail.protection.outlook.com (10.152.20.238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17 via Frontend Transport; Sat, 1 Aug 2020 23:34:18 +0000 Received: ("Tessian outbound c4059ed8d7bf:v62"); Sat, 01 Aug 2020 23:34:18 +0000 X-CR-MTA-TID: 64aa7808 Received: from e4b426220911.2 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 514ADE1D-0C65-475F-9406-1F0095D3B5F7.1; Sat, 01 Aug 2020 23:34:12 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e4b426220911.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Sat, 01 Aug 2020 23:34:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K7U4iyAcrMpeik5/H8VaJFbNzhpTizw6Y3+N9fKC3Q2y8pd/L8vNIE7ziMNZ+v1VKLajTWQvMRkcQeTWcKduco0krGfcLGQhLXsqQsFLg+dKqbONz/XepnU2+qZPUHfkyp8vzdRY9vZ70z9f1g2/0jXFC+RafnHXGgeb5xFvphwIEIfm5U1CLSAaSCCAmexk92IRdJ9rYr91I1wr4s4utVs9p0XOYnLQz82AsEGbCyhE8PPjtfBcuCqdr9PpqrU8B9SBwuJsS7uJIriW1ZYAFf5rGU/RzezNGSot061sbqCWARIb64gm6o+Y3lkTKwWFeprKChSzw7rOUryDnc9crA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E+xSoZO9uMygQexSpH2gQajncEFzOkifg+xJRKz3cEg=; b=Tpoc95JZIrHw1WVjaG6gIFMssTEnws6TH85GQKn+PlWHgyr+bhK+QhtHtXnkU3zpFv8985Jv+aVDJOx1QJreJoMw5FI5YuRzvlCPscGOVW+V5/C3EgAaNzUPfSBQQV0F6CHi/tYyLoTh2rw+NzLcPvBlrHmpCYzz+qky6UtUyAu6vA7quHyJvyS2wJElDIT/XQRt/96r5hzblVMLATtdH3epXIeCJP6e+wuchS3mH+ltAQVME+kF6pIt08bCflaOlV4QkYO4EayufErTdAf7I4ujlbrlyFAEvfY1WR0m2aCNFP5Ovkdl9qeIPwBEKT8fsxyJIKFeXUuetPpb5VBA4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E+xSoZO9uMygQexSpH2gQajncEFzOkifg+xJRKz3cEg=; b=gFDZK9eCPElw0PF1Pjw3kd6XzXN/2TonhCUV+FQAO44j8rS+5QLCwmECAFA5vBhwK3ELl3ACY0A5xLcRpQnL4ExTzFfoEAaWbbSfUFotY3KQoyJl7vCnquxPsw1nBYFF8ASpljMLQj3P4K+p1AD9gmmhXd1UF8f6igqNESyNnZc= Received: from DB6PR0802MB2216.eurprd08.prod.outlook.com (2603:10a6:4:85::9) by DB8PR08MB5195.eurprd08.prod.outlook.com (2603:10a6:10:bf::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.17; Sat, 1 Aug 2020 23:34:11 +0000 Received: from DB6PR0802MB2216.eurprd08.prod.outlook.com ([fe80::9d1d:207b:e89d:199d]) by DB6PR0802MB2216.eurprd08.prod.outlook.com ([fe80::9d1d:207b:e89d:199d%10]) with mapi id 15.20.3239.021; Sat, 1 Aug 2020 23:34:11 +0000 From: Honnappa Nagarahalli To: Gaurav Singh , "dev@dpdk.org" CC: nd , Honnappa Nagarahalli , nd Thread-Topic: [dpdk-dev] [PATCH] librte_metrics: fix memory leak Thread-Index: AQHWZ8oyV/Fv/mbli0auUmXgpnzk0akj5EBQ Date: Sat, 1 Aug 2020 23:34:10 +0000 Message-ID: References: <20200731034520.30791-1-gaurav1086@gmail.com> <20200801060838.20591-1-gaurav1086@gmail.com> In-Reply-To: <20200801060838.20591-1-gaurav1086@gmail.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ts-tracking-id: 1866c213-7a89-4c09-92a6-5831a074e005.0 x-checkrecipientchecked: true Authentication-Results-Original: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com; x-originating-ip: [217.140.110.7] x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9f1b4271-524d-4dbd-9204-08d8367368ce x-ms-traffictypediagnostic: DB8PR08MB5195:|VI1PR0801MB1792: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true nodisclaimer: true x-ms-oob-tlc-oobclassifiers: OLM:2512;OLM:2512; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Hj8zZUVZ1TL5rGQEWJiloWIoTq4yjc+aFr24SJ7YC/dGxQWtspfZkmnx/QBwv33TLNvYgm9TzJraEodQ+fb/LaBJJee6vlpSKz5PbbAYAgYnW6ekwZ6vzoHFaC8p03rVIjjDsMmEWXNuPcjhGmknYQvXKjiqCNZ7ERWRWT09m7pXtJtQg3GzF7QPsOoRCwY13npJCyoo16p6RZTT8UkblFNhSEHgIutc97zIaHSlxvCsRlVd4CMovo8B+Yz85JlIvUIT4yksG/KZKaI6Z+mOeidBJAO0QTeZoT/y5bTE/5W2rx9+uxqB+LYayRH/fDzCfh++NZsqOB1e9rKqJiK98bIuGEtSzVCXOOZhhT9n7ZW8fF8mCS2MSB5PBsP09a1+aLbI5MuDC3pyONVNNVr4HQ== X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB6PR0802MB2216.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(376002)(136003)(366004)(396003)(39850400004)(346002)(53546011)(6506007)(966005)(26005)(316002)(2906002)(110136005)(54906003)(7696005)(86362001)(76116006)(83380400001)(71200400001)(9686003)(66946007)(64756008)(66446008)(66476007)(66556008)(55016002)(5660300002)(52536014)(186003)(8676002)(4326008)(33656002)(478600001)(8936002); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: aN48QTH9IUByaApkGF9lXy3feriSsQjSuMfPSnsgAfSHmu6+MLQRqhiU/np2n5c8qpCbf8QK8KgwzmX+o16PMI2aG9/XVSJeiojZBguFrp9qvkOHTRCUlQ+PNokoKoCbtne+nuRZx6ZTcXJ0tuTAPqGVbOj7Axt9eou0JjM2zSEXSGXR6NnDX+7xfSbTlxPFnm43SNsi5xh6b8YWwShQVYDDO4hLkd6ltvQTbbXBhn3FzHC08OB2S5mrbVEx/KEfOmlenR1x/StsVAxowThDGEjdLm2aC6EoSQueUDZC2iX//mEG9oKG6lcYQ31T5pZZzV2UMElSFP91jsbOQusZ2/bDL0xX0rQxVhobX3M8f95b/DtMP2AwchKvW83GZY/sEK3WBaf4ZktWZgKcry6Da9hAXpReh+HAHCLBn3E+E8Mtc0Tpkapn3gEIzh7i92Gwfg1h/sLbFZ2IH6yImC2BPAewEyZ0GXv+3p/YHLC+tO4d0Ceo9AVBJKAlcY72Ib9tTn2es7kSUxs4ZS20W7aicCbMmmXDP1PNd871tA+Qru67k1PPX9nHwm0Q/3u4f8PTYn9N+sYS5zyIK2DWPVv4zQPIuny075woTHHUjCjSTJoN+i5b60nHT4+OCeVtOht4Mi+ouwVh8r6Ku/EW1qdI/A== Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5195 Original-Authentication-Results: gmail.com; dkim=none (message not signed) header.d=none;gmail.com; dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 3df440d0-03d8-4ee8-03a5-08d8367364af X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d372ZnEZmvuRzDnrDsDDOEO9p7nVbgFcZDCdCp3yG07cUjHWsGeNchdNfIspvm2y7E4oR86rUIAPiTWqJhRftqnHRKD3XRh1ArDKVf/kza21FK7u+eQW13pv6FmRZgwc/FoaY+N3/01+rFMSJ4TrT+k/pxzlFpFmMfIgx7baulAGsCGweyIauGAbvUIZ/GsBbSsPnKkTghMzP9C8ac2XxpBDlRtX57XcJd5p9pdAhSkSlmGpnUNHpbGZaCYvUeZYJcGnGXPFvg+frHOf8A4xPHh197K8pJxkz1EErEsIueZ1/VJLUg8ksoY3vFjP3ZuUh2pNh/HU/7qwdyrxlQAnQ2KM/OsNla/96RzSTZ8AOWnSp6QRKR5QTGieMCSslfH42hCiwmKlxDooK/r+QIN8EcTgtnXt3AY7bmiyiZS1m/Oid3iO3e37rX4rCa5nLjI71zuY/gYOlHocAt4ycbtUeaNWR5q1DMbpR8hHvBH8dCA= X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFTY:; SFS:(4636009)(396003)(39850400004)(136003)(376002)(346002)(46966005)(83380400001)(316002)(8936002)(966005)(86362001)(81166007)(8676002)(4326008)(110136005)(478600001)(2906002)(82740400003)(356005)(82310400002)(9686003)(47076004)(52536014)(55016002)(33656002)(5660300002)(7696005)(70586007)(6506007)(53546011)(70206006)(26005)(336012)(186003)(54906003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Aug 2020 23:34:18.0322 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9f1b4271-524d-4dbd-9204-08d8367368ce X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DB5EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1792 Subject: Re: [dpdk-dev] [PATCH] librte_metrics: fix memory leak X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Hi Gaurav, Thanks for the fix. Few comments inline. Also, please follow contributing = guidelines [1]. There is a cheat sheet [2] which is very helpful. [1] https://doc.dpdk.org/guides/contributing/index.html [2] https://doc.dpdk.org/guides/contributing/cheatsheet.html > -----Original Message----- > From: dev On Behalf Of Gaurav Singh > Sent: Saturday, August 1, 2020 1:09 AM > To: dev@dpdk.org > Cc: Gaurav Singh > Subject: [dpdk-dev] [PATCH] librte_metrics: fix memory leak ^^^^^^^^^^^^ should = be 'lib/metrics' >=20 >=20 > Fix memory leak issue >=20 Needs "Fixes" tag and Cc to stable@dpdk.org (check the contribution guideli= nes) > Signed-off-by: Gaurav Singh > --- > lib/librte_metrics/rte_metrics_telemetry.c | 24 +++++++++++++++------- > 1 file changed, 17 insertions(+), 7 deletions(-) >=20 > diff --git a/lib/librte_metrics/rte_metrics_telemetry.c > b/lib/librte_metrics/rte_metrics_telemetry.c > index 289ebae0b..9fbe59c62 100644 > --- a/lib/librte_metrics/rte_metrics_telemetry.c > +++ b/lib/librte_metrics/rte_metrics_telemetry.c > @@ -41,12 +41,19 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t > port_id) > } >=20 > xstats_names =3D malloc(sizeof(*xstats_names) * num_xstats); > + if (xstats_names =3D=3D NULL) { > + METRICS_LOG_ERR("Failed to malloc memory for > xstats_names"); > + ret =3D -ENOMEM; > + return ret; You can return -ENOMEM directly without assigning it to 'ret' > + } > + > eth_xstats_names =3D malloc(sizeof(struct rte_eth_xstat_name) > * num_xstats); > - if (eth_xstats_names =3D=3D NULL || xstats_names =3D=3D NULL) { > + if (eth_xstats_names =3D=3D NULL) { > METRICS_LOG_ERR("Failed to malloc memory for > xstats_names"); ^^^^^^^^^^^^ I think it is worth changing to eth_xstats_names > ret =3D -ENOMEM; > - goto free_xstats; > + free(xstats_names); > + return ret; Same here, return -ENOMEM directly > } >=20 > if (rte_eth_xstats_get_names(port_id, > @@ -54,7 +61,7 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t > port_id) > METRICS_LOG_ERR("rte_eth_xstats_get_names(%u) len %d > failed", > port_id, num_xstats); > ret =3D -EPERM; > - goto free_xstats; > + return ret; Any reason for this change? This change leaks memory. > } >=20 > for (i =3D 0; i < num_xstats; i++) > @@ -63,9 +70,6 @@ rte_metrics_tel_reg_port_ethdev_to_metrics(uint16_t > port_id) > if (ret < 0) > METRICS_LOG_ERR("rte_metrics_reg_names failed - metrics > may already be registered"); >=20 > -free_xstats: > - free(eth_xstats_names); > - free(xstats_names); Any reason for this change? This is leaking memory in the successful case. > return ret; > } >=20 > @@ -167,9 +171,15 @@ rte_metrics_tel_format_port(uint32_t pid, json_t > *ports, > } >=20 > metrics =3D malloc(sizeof(struct rte_metric_value) * num_metrics); > + if (metrics =3D=3D NULL) { > + METRICS_LOG_ERR("Cannot allocate memory"); > + return -ENOMEM; > + } > + > names =3D malloc(sizeof(struct rte_metric_name) * num_metrics); > - if (metrics =3D=3D NULL || names =3D=3D NULL) { > + if (names =3D=3D NULL) { > METRICS_LOG_ERR("Cannot allocate memory"); > + free(metrics); > return -ENOMEM; > } >=20 > -- > 2.17.1