]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: chunks: release trash also in deinit
authorWilly Tarreau <w@1wt.eu>
Wed, 27 Apr 2022 15:55:41 +0000 (17:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 27 Apr 2022 15:55:41 +0000 (17:55 +0200)
Tim reported in issue #1676 that just like startup_logs, trash buffers
are not released on deinit since they're thread-local, but valgrind
notices it when quitting before creating threads like "-c -f ...". Let's
just subscribe the function to deinit in addition to threads' end.

The two "free(x);x=NULL;" in free_trash_buffers_per_thread() were
also simplified using ha_free().

src/chunk.c

index 5c720c1bcdef493d5bf718f70799515f2915667b..d67e9f1d27e200cdb08b7fe80bae4c38a578bfc4 100644 (file)
@@ -82,10 +82,8 @@ static int alloc_trash_buffers_per_thread()
 static void free_trash_buffers_per_thread()
 {
        chunk_destroy(&trash);
-       free(trash_buf2);
-       free(trash_buf1);
-       trash_buf2 = NULL;
-       trash_buf1 = NULL;
+       ha_free(&trash_buf2);
+       ha_free(&trash_buf1);
 }
 
 /* Initialize the trash buffers. It returns 0 if an error occurred. */
@@ -309,6 +307,7 @@ int chunk_strcasecmp(const struct buffer *chk, const char *str)
 
 REGISTER_PER_THREAD_ALLOC(alloc_trash_buffers_per_thread);
 REGISTER_PER_THREAD_FREE(free_trash_buffers_per_thread);
+REGISTER_POST_DEINIT(free_trash_buffers_per_thread);
 
 /*
  * Local variables: