]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: deinit: release the in-memory copy of shared libs
authorWilly Tarreau <w@1wt.eu>
Fri, 29 May 2026 09:20:12 +0000 (11:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 1 Jun 2026 13:01:32 +0000 (15:01 +0200)
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().

include/haproxy/tools.h
src/haproxy.c
src/tools.c

index 5d05a1cfeba51da767659b811da144ea3ee39bcb..ff1ba8bc1843f8d2a523aab4b3681ffbdf2d9a99 100644 (file)
@@ -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.
index 3f0e097bf5d825db142f21da1c5161b1602c8187..b38b13d78d68803bce6e2691effbc2d68c46b085 100644 (file)
@@ -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)
index 429cd04a05c163d2c48efe3acda199a13ff2e39f..b9a0da783e74c703381ae8e8c36b9b0e9064d9d6 100644 (file)
@@ -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
 
 /*