From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 309022C18; Fri, 5 May 2017 16:47:25 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 May 2017 07:47:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,292,1491289200"; d="scan'208";a="964854769" Received: from silpixa00390851.ir.intel.com ([10.237.223.109]) by orsmga003.jf.intel.com with ESMTP; 05 May 2017 07:47:23 -0700 From: Roman Korynkevych To: dev@dpdk.org Cc: harry.van.haaren@intel.com, maryam.tahhan@intel.com, Roman Korynkevych , stable@dpdk.org Date: Fri, 5 May 2017 15:47:29 +0100 Message-Id: <1493995649-3220-1-git-send-email-romanx.korynkevych@intel.com> X-Mailer: git-send-email 2.1.0 Subject: [dpdk-dev] [PATCH v1 1/1] app/procinfo: resource leak fix. 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: Fri, 05 May 2017 14:47:26 -0000 Coverity issue: 143256 Fixes: 2deb6b5246d7706448d070335b329d1acb754cee ("app/procinfo: add collectd format and host id") Cc: stable@dpdk.org Signed-off-by: Roman Korynkevych --- app/proc_info/main.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/proc_info/main.c b/app/proc_info/main.c index 17a1c87..3d0b621 100644 --- a/app/proc_info/main.c +++ b/app/proc_info/main.c @@ -75,7 +75,7 @@ static uint32_t enable_xstats; /**< Enable collectd format*/ static uint32_t enable_collectd_format; /**< FD to send collectd format messages to STDOUT*/ -static int stdout_fd; +static int stdout_fd = -1; /**< Host id process is running on */ static char host_id[MAX_LONG_OPT_SZ]; /**< Enable metrics. */ @@ -637,28 +637,37 @@ main(int argc, char **argv) argc += 3; ret = rte_eal_init(argc, argp); - if (ret < 0) + if (ret < 0) { + close(stdout_fd); rte_panic("Cannot init EAL\n"); + } argc -= ret; argv += (ret - 3); - if (!rte_eal_primary_proc_alive(NULL)) + if (!rte_eal_primary_proc_alive(NULL)) { + close(stdout_fd); rte_exit(EXIT_FAILURE, "No primary DPDK process is running.\n"); + } /* parse app arguments */ ret = proc_info_parse_args(argc, argv); - if (ret < 0) + if (ret < 0) { + close(stdout_fd); rte_exit(EXIT_FAILURE, "Invalid argument\n"); + } if (mem_info) { meminfo_display(); + close(stdout_fd); return 0; } nb_ports = rte_eth_dev_count(); - if (nb_ports == 0) + if (nb_ports == 0) { + close(stdout_fd); rte_exit(EXIT_FAILURE, "No Ethernet ports - bye\n"); + } /* If no port mask was specified*/ if (enabled_port_mask == 0) @@ -688,5 +697,7 @@ main(int argc, char **argv) if (enable_metrics) metrics_display(RTE_METRICS_GLOBAL); + close(stdout_fd); + return 0; } -- 2.1.0