service: fix memory leak with new function
[dpdk.git] / lib / librte_eal / common / rte_service.c
index 5f97d85..bcd644a 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,26 @@ 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;
+}
+
+void rte_service_finalize(void)
+{
+       if (!rte_service_library_initialized)
+               return;
+
+       if (rte_services)
+               rte_free(rte_services);
+
+       if (lcore_states)
+               rte_free(lcore_states);
+
+       rte_service_library_initialized = 0;
 }
 
 /* returns 1 if service is registered and has not been unregistered