From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id B0D8B2BE5; Wed, 24 Jan 2018 18:03:01 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jan 2018 09:03:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,408,1511856000"; d="scan'208";a="198471614" Received: from silpixa00398672.ir.intel.com ([10.237.223.111]) by fmsmga006.fm.intel.com with ESMTP; 24 Jan 2018 09:02:58 -0800 From: Harry van Haaren To: dev@dpdk.org Cc: vipin.varghese@intel.com, Harry van Haaren , stable@dpdk.org Date: Wed, 24 Jan 2018 17:02:47 +0000 Message-Id: <1516813367-163213-1-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-stable] [PATCH] service: fix possible mem leak on initialize X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Jan 2018 17:03:02 -0000 This commit ensures that if that if we run out of memory during the initialization of the service library, that the first allocated memory is correctly freed instead of leaked. Fixes: 21698354c832 ("service: introduce service cores concept") Cc: stable@dpdk.org Reported-by: Vipin Varghese Signed-off-by: Harry van Haaren --- lib/librte_eal/common/rte_service.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index 5f97d85..b40c3d9 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -82,14 +82,14 @@ int32_t rte_service_init(void) RTE_CACHE_LINE_SIZE); if (!rte_services) { printf("error allocating rte services array\n"); - return -ENOMEM; + goto fail_mem; } lcore_states = rte_calloc("rte_service_core_states", RTE_MAX_LCORE, sizeof(struct core_state), RTE_CACHE_LINE_SIZE); if (!lcore_states) { printf("error allocating core states array\n"); - return -ENOMEM; + goto fail_mem; } int i; @@ -106,6 +106,12 @@ int32_t rte_service_init(void) rte_service_library_initialized = 1; return 0; +fail_mem: + if (rte_services) + rte_free(rte_services); + if (lcore_states) + rte_free(lcore_states); + return -ENOMEM; } /* returns 1 if service is registered and has not been unregistered -- 2.7.4