From: Vipin Varghese Date: Fri, 26 Jan 2018 20:55:36 +0000 (+0530) Subject: service: fix memory leak with new function X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=da23f0aa87d83e481295ceb5283a34232c336f36;p=dpdk.git service: fix memory leak with new function The rte_service_finalize routine checks if service is initialized or not. If yes; releases internal memory for services and lcore states are freed. This routine is to be invoked at end of application termination. Fixes: 21698354c832 ("service: introduce service cores concept") Cc: stable@dpdk.org Signed-off-by: Vipin Varghese Acked-by: Harry van Haaren --- diff --git a/lib/librte_eal/common/include/rte_service.h b/lib/librte_eal/common/include/rte_service.h index 02b1512f64..5e3e3a66ed 100644 --- a/lib/librte_eal/common/include/rte_service.h +++ b/lib/librte_eal/common/include/rte_service.h @@ -429,6 +429,17 @@ int32_t rte_service_attr_get(uint32_t id, uint32_t attr_id, */ int32_t rte_service_attr_reset_all(uint32_t id); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * Free up the memory that has been initialized. This routine + * is to be invoked prior to process termination. + * + * @retval None + */ +void rte_service_finalize(void); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index b40c3d97f2..bcd644a8a4 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -114,6 +114,20 @@ fail_mem: 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 * Returns 0 if service never registered, or has been unregistered */ diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 7088b72306..1a8b1b5efd 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -223,6 +223,7 @@ EXPERIMENTAL { rte_service_component_unregister; rte_service_component_runstate_set; rte_service_dump; + rte_service_finalize; rte_service_get_by_id; rte_service_get_by_name; rte_service_get_count;