From 374b0e9942bb87dd8d0c956d7c03c85dcc489bf7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 31 Mar 2022 23:25:35 -0700 Subject: [PATCH] Work around memory-leak false alarms Problem reported by Raphael Isemann in: https://lists.gnu.org/r/autoconf-patches/2022-03/msg00007.html * lib/autoconf/c.m4 (_AC_C_C99_TEST_MAIN, AC_C_FLEXIBLE_ARRAY_MEMBER): * tests/data/gnulib_std_gnu11_2020_08_17.m4 (_AC_C_C99_TEST_HEADER): Free storage allocated via malloc, to pacify overly-picky implementations that issue false alarms about memory leaks. --- lib/autoconf/c.m4 | 6 +++++- tests/data/gnulib_std_gnu11_2020_08_17.m4 | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index 48bd49a3..42fbcbd0 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -1330,6 +1330,8 @@ ac_c_conftest_c99_main=' ia->datasize = 10; for (int i = 0; i < ia->datasize; ++i) ia->data[i] = i * 1.234; + // Work around memory leak warnings. + free (ia); // Check named initializers. struct named_init ni = { @@ -2170,7 +2172,9 @@ AC_DEFUN([AC_C_FLEXIBLE_ARRAY_MEMBER], struct s *p = (struct s *) malloc (offsetof (struct s, d) + m * sizeof (double)); p->d[0] = 0.0; - return p->d != (double *) NULL;]])], + m = p->d != (double *) NULL; + free (p); + return m;]])], [ac_cv_c_flexmember=yes], [ac_cv_c_flexmember=no])]) if test $ac_cv_c_flexmember = yes; then diff --git a/tests/data/gnulib_std_gnu11_2020_08_17.m4 b/tests/data/gnulib_std_gnu11_2020_08_17.m4 index da52cd6f..21f7cc7a 100644 --- a/tests/data/gnulib_std_gnu11_2020_08_17.m4 +++ b/tests/data/gnulib_std_gnu11_2020_08_17.m4 @@ -319,6 +319,8 @@ AC_DEFUN([_AC_C_C99_TEST_BODY], ia->datasize = 10; for (int i = 0; i < ia->datasize; ++i) ia->data[i] = i * 1.234; + // Work around memory leak warnings. + free (ia); // Check named initializers. struct named_init ni = { -- 2.32.0