From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 75DCB1B652 for ; Wed, 31 Jan 2018 15:30:34 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 06:30:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,440,1511856000"; d="scan'208";a="26206504" Received: from silpixa00391537.ir.intel.com (HELO silpixa00391537.ger.corp.intel.com) ([10.237.222.189]) by fmsmga004.fm.intel.com with ESMTP; 31 Jan 2018 06:30:31 -0800 From: Amr Mokhtar To: dev@dpdk.org Cc: Amr Mokhtar Date: Wed, 31 Jan 2018 14:30:29 +0000 Message-Id: <1517409029-131237-1-git-send-email-amr.mokhtar@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] examples/bbdev: 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: , X-List-Received-Date: Wed, 31 Jan 2018 14:30:34 -0000 xstats and xstats_names buffers were allocated for the purpose of printing eth_xstats, but were not freed before exit. A fix is added to free before exit points. Coverity issue: 257013 Fixes: 1ffee690eaa1 ("examples/bbdev: add sample app") Signed-off-by: Amr Mokhtar --- examples/bbdev_app/main.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/bbdev_app/main.c b/examples/bbdev_app/main.c index 2e5bd8c..ef0ca25 100644 --- a/examples/bbdev_app/main.c +++ b/examples/bbdev_app/main.c @@ -585,21 +585,28 @@ print_stats(struct stats_lcore_params *stats_lcore) "Failed to calloc memory for xstats"); ret = rte_eth_xstats_get(port_id, xstats, len); - if (ret < 0 || ret > len) + if (ret < 0 || ret > len) { + free(xstats); rte_exit(EXIT_FAILURE, "rte_eth_xstats_get(%u) len%i failed: %d", port_id, len, ret); + } xstats_names = calloc(len, sizeof(*xstats_names)); - if (xstats_names == NULL) + if (xstats_names == NULL) { + free(xstats); rte_exit(EXIT_FAILURE, "Failed to calloc memory for xstats_names"); + } ret = rte_eth_xstats_get_names(port_id, xstats_names, len); - if (ret < 0 || ret > len) + if (ret < 0 || ret > len) { + free(xstats); + free(xstats_names); rte_exit(EXIT_FAILURE, "rte_eth_xstats_get_names(%u) len%i failed: %d", port_id, len, ret); + } for (i = 0; i < len; i++) { if (xstats[i].value > 0) @@ -630,6 +637,9 @@ print_stats(struct stats_lcore_params *stats_lcore) continue; print_lcore_stats(stats_lcore->lconf[l_id].lcore_stats, l_id); } + + free(xstats); + free(xstats_names); } static int -- 2.7.4