From acbbfa8a943d113716d11f59a2b5f13acb929e47 Mon Sep 17 00:00:00 2001 From: Boian Bonev Date: Tue, 14 Dec 2021 21:56:06 +0200 Subject: [PATCH] Prefer usage of mallinfo2 over mallinfo --- configure.ac | 2 ++ src/shared/selinux-util.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 4e18a57be..85a524a61 100644 --- a/configure.ac +++ b/configure.ac @@ -232,6 +232,8 @@ AC_SUBST(sushell) # selinux-util.c uses struct mallinfo which is not available for all C libraries (musl). AC_CHECK_FUNCS([mallinfo]) +# mallinfo is deprecated, prefer to use mallinfo2 when available +AC_CHECK_FUNCS([mallinfo2]) # ------------------------------------------------------------------------------ diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c index e05322817..84e45e3b7 100644 --- a/src/shared/selinux-util.c +++ b/src/shared/selinux-util.c @@ -69,7 +69,9 @@ int mac_selinux_init(const char *prefix) { #ifdef HAVE_SELINUX usec_t before_timestamp, after_timestamp; -#ifdef HAVE_MALLINFO +#ifdef HAVE_MALLINFO2 + struct mallinfo2 before_mallinfo, after_mallinfo; +#elif HAVE_MALLINFO struct mallinfo before_mallinfo, after_mallinfo; #endif @@ -79,7 +81,9 @@ int mac_selinux_init(const char *prefix) { if (label_hnd) return 0; -#ifdef HAVE_MALLINFO +#ifdef HAVE_MALLINFO2 + before_mallinfo = mallinfo2(); +#elif HAVE_MALLINFO before_mallinfo = mallinfo(); #endif @@ -100,15 +104,19 @@ int mac_selinux_init(const char *prefix) { } else { char timespan[FORMAT_TIMESPAN_MAX]; -#ifdef HAVE_MALLINFO +#if defined(HAVE_MALLINFO)|defined(HAVE_MALLINFO2) int l; #endif after_timestamp = now(CLOCK_MONOTONIC); -#ifdef HAVE_MALLINFO +#ifdef HAVE_MALLINFO2 + after_mallinfo = mallinfo2(); +#elif HAVE_MALLINFO after_mallinfo = mallinfo(); +#endif +#if defined(HAVE_MALLINFO)|defined(HAVE_MALLINFO2) l = after_mallinfo.uordblks > before_mallinfo.uordblks ? after_mallinfo.uordblks - before_mallinfo.uordblks : 0; log_debug("Successfully loaded SELinux database in %s, size on heap is %iK.",