From bbcc4f0bc9e4b2ef89af4677d67f0ee17beb10ac Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Sun, 27 Nov 2022 16:28:12 +1100 Subject: [PATCH] fix memory leak --- src/lib66/service/service_graph_collect.c | 29 ++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/lib66/service/service_graph_collect.c b/src/lib66/service/service_graph_collect.c index 6ad9312d..553b0ea5 100644 --- a/src/lib66/service/service_graph_collect.c +++ b/src/lib66/service/service_graph_collect.c @@ -51,6 +51,9 @@ void service_graph_collect(graph_t *g, char const *alist, size_t alen, resolve_s if (service_resolve_array_search(ares, (*areslen), name) < 0) { resolve_service_t res = RESOLVE_SERVICE_ZERO ; + /** need to make a copy of the resolve due of the freed + * of the wres struct at the end of the process */ + resolve_service_t cp = RESOLVE_SERVICE_ZERO ; wres = resolve_set_struct(DATA_SERVICE, &res) ; if (FLAGS_ISSET(flag, STATE_FLAGS_TOINIT)) @@ -64,12 +67,26 @@ void service_graph_collect(graph_t *g, char const *alist, size_t alen, resolve_s if (!state_read(&ste, res.sa.s + res.path.home, name)) log_dieu(LOG_EXIT_SYS, "read state file of: ", name, " -- please make a bug report") ; - if (service_is(&ste, STATE_FLAGS_ISSUPERVISED)) - ares[(*areslen)++] = res ; - else + if (service_is(&ste, STATE_FLAGS_ISSUPERVISED)) { + + if (!service_resolve_copy(&cp, &res)) + log_dieu(LOG_EXIT_SYS, "copy resolve file of: ", name, " -- please make a bug report") ; + + ares[(*areslen)++] = cp ; + + } else { + + resolve_free(wres) ; continue ; - } else - ares[(*areslen)++] = res ; + } + + } else { + + if (!service_resolve_copy(&cp, &res)) + log_dieu(LOG_EXIT_SYS, "copy resolve file of: ", name, " -- please make a bug report") ; + + ares[(*areslen)++] = cp ; + } if (FLAGS_ISSET(flag, STATE_FLAGS_TOPROPAGATE)) { @@ -88,9 +105,9 @@ void service_graph_collect(graph_t *g, char const *alist, size_t alen, resolve_s service_graph_collect(g, sa.s, sa.len, ares, areslen, info, flag) ; } } + resolve_free(wres) ; } } - free(wres) ; stralloc_free(&sa) ; } -- GitLab