Fix memoryleak in conftest.c

Raphael Isemann <[email protected]> Thu, 31 Mar 2022 11:31:23 +0200
Newsgroups gmane.comp.sysutils.autoconf.patches
Message-ID <CADrqtg4OMxG2DUAq0sFTYtVzkcLsVsrJE9js7WHdyHpEi3w+sQ@mail.gmail.com>
Hi,

The attached patch fixes a memory leak in the conftest.c file. I'm
aware this code is only test compiled and never executed so there is
no actual leak, but the obvious memory leak here is causing problems
with a downstream compiler (the compiler is more strict about memory
leaks and keeps generating warnings when used in autoconf projects
that compile this file during configure).

Thanks,
- Raphael Isemann
autoconf-leak.diff (text/x-patch, 939 B)
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index 48bd49a3..ae0a89cd 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1319,28 +1319,29 @@ ac_c_conftest_c99_main='
   if (test_restrict ("String literal") == 0)
     success = true;
   char *restrict newvar = "Another string";
 
   // Check varargs.
   success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234);
   test_varargs_macros ();
 
   // Check flexible array members.
   struct incomplete_array *ia =
     malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10));
   ia->datasize = 10;
   for (int i = 0; i < ia->datasize; ++i)
     ia->data[i] = i * 1.234;
+  free(ia);
 
   // Check named initializers.
   struct named_init ni = {
     .number = 34,
     .name = L"Test wide string",
     .average = 543.34343,
   };
 
   ni.number = 58;
 
   int dynamic_array[ni.number];
   dynamic_array[0] = argv[0][0];
   dynamic_array[ni.number - 1] = 543;