DPDK patches and discussions
 help / color / mirror / Atom feed
From: Harry van Haaren <harry.van.haaren@intel.com>
To: dev@dpdk.org
Cc: vipin.varghese@intel.com,
	Harry van Haaren <harry.van.haaren@intel.com>,
	stable@dpdk.org
Subject: [dpdk-dev] [PATCH] service: fix possible mem leak on initialize
Date: Wed, 24 Jan 2018 17:02:47 +0000	[thread overview]
Message-ID: <1516813367-163213-1-git-send-email-harry.van.haaren@intel.com> (raw)

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 <vipin.varghese@intel.com>
Signed-off-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 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

             reply	other threads:[~2018-01-24 17:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 17:02 Harry van Haaren [this message]
2018-01-25 22:12 ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1516813367-163213-1-git-send-email-harry.van.haaren@intel.com \
    --to=harry.van.haaren@intel.com \
    --cc=dev@dpdk.org \
    --cc=stable@dpdk.org \
    --cc=vipin.varghese@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).