From: Willy Tarreau Date: Fri, 29 May 2026 09:20:12 +0000 (+0200) Subject: MINOR: deinit: release the in-memory copy of shared libs X-Git-Tag: v3.4.0~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8fd6d25d8d12035f7f810470ac6a6a30c0aa34e;p=thirdparty%2Fhaproxy.git MINOR: deinit: release the in-memory copy of shared libs When shared libs were loaded via "set-dumpable libs", better release them upon deinit, it will make valgrind happier. For this we now have a new function free_collected_libs() in tools.c and call it in deinit(). --- diff --git a/include/haproxy/tools.h b/include/haproxy/tools.h index 5d05a1cfe..ff1ba8bc1 100644 --- a/include/haproxy/tools.h +++ b/include/haproxy/tools.h @@ -1154,6 +1154,7 @@ void *get_sym_curr_addr(const char *name); void *get_sym_next_addr(const char *name); int dump_libs(struct buffer *output, int with_addr); void collect_libs(void); +void free_collected_libs(void); /* Note that this may result in opening libgcc() on first call, so it may need * to have been called once before chrooting. diff --git a/src/haproxy.c b/src/haproxy.c index 3f0e097bf..b38b13d78 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2956,7 +2956,7 @@ void deinit(void) free(init_env); } free(progname); - + free_collected_libs(); } /* end deinit() */ __attribute__((noreturn)) void deinit_and_exit(int status) diff --git a/src/tools.c b/src/tools.c index 429cd04a0..b9a0da783 100644 --- a/src/tools.c +++ b/src/tools.c @@ -6151,6 +6151,17 @@ void collect_libs(void) /* don't need the temporary storage anymore */ ha_free(&ctx.storage); } + +/* release memory associated to collected libs */ +void free_collected_libs(void) +{ + if (!lib_storage || !lib_size) + return; + munmap(lib_storage, lib_size); + lib_storage = NULL; + lib_size = 0; +} + # else // no DL_ITERATE_PHDR # error "No dump_libs() function for this platform" # endif @@ -6167,6 +6178,11 @@ void collect_libs(void) { } +/* unsupported platform: nothing to free */ +void free_collected_libs(void) +{ +} + #endif // HA_HAVE_DUMP_LIBS /*