]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: use mallinfo2() when available instead of mallinfo()
authorWilly Tarreau <w@1wt.eu>
Thu, 16 Sep 2021 07:18:21 +0000 (09:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 16 Sep 2021 07:20:16 +0000 (09:20 +0200)
Ilya reported in issue #1391 a build warning on Fedora about mallinfo()
being deprecated in favor of mallinfo2() since glibc-2.33. Let's add
support for it. This should be backported where the following commit is
also backported: 157e39303 ("MINOR: pools: automatically disable
malloc_trim() with external allocators").

include/haproxy/compat.h
src/pool.c

index 84cdbe0d5e90902fb407691a6e7d9c72cb372c90..19a5317860efd349788415abc5bf62ac0ab7be97 100644 (file)
@@ -282,6 +282,12 @@ typedef struct { } empty_t;
 #define HA_HAVE_FAST_MALLOC
 #endif
 
+/* glibc 2.33 provides mallinfo2() that overcomes mallinfo()'s type limitations */
+#if (defined(__GNU_LIBRARY__) && (__GLIBC__ > 2 || __GLIBC__ == 2 && __GLIBC_MINOR__ >= 33))
+#include <malloc.h>
+#define HA_HAVE_MALLINFO2
+#endif
+
 /* FreeBSD also has malloc_usable_size() but it requires malloc_np.h */
 #if defined(USE_MEMORY_PROFILING) && defined(__FreeBSD__) && (__FreeBSD_version >= 700002)
 #include <malloc_np.h>
index 94bbb8355769453e0e31526dbf7c9b45fd5520df..ad63d9ba30175746dafe181e0c288f8f34dd3c73 100644 (file)
@@ -58,12 +58,24 @@ static void trim_all_pools(void)
  */
 static void detect_allocator(void)
 {
+#ifdef HA_HAVE_MALLINFO2
+       struct mallinfo2 mi1, mi2;
+#else
        struct mallinfo mi1, mi2;
+#endif
        void *ptr;
 
+#ifdef HA_HAVE_MALLINFO2
+       mi1 = mallinfo2();
+#else
        mi1 = mallinfo();
+#endif
        ptr = DISGUISE(malloc(1));
+#ifdef HA_HAVE_MALLINFO2
+       mi2 = mallinfo2();
+#else
        mi2 = mallinfo();
+#endif
        free(DISGUISE(ptr));
 
        using_libc_allocator = !!memcmp(&mi1, &mi2, sizeof(mi1));