]> git.droids-corp.org - dpdk.git/commitdiff
service: fix possible mem leak on initialize
authorHarry van Haaren <harry.van.haaren@intel.com>
Wed, 24 Jan 2018 17:02:47 +0000 (17:02 +0000)
committerThomas Monjalon <thomas@monjalon.net>
Thu, 25 Jan 2018 22:11:44 +0000 (23:11 +0100)
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

index 5f97d85175c8866b8089940a5a7f95c169c54660..b40c3d97f2999a3e503949d0fffde900257e74d1 100644 (file)
@@ -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