[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: results of gnulib tests with -fsanitize=address
From: |
Bruno Haible |
Subject: |
Re: results of gnulib tests with -fsanitize=address |
Date: |
Sat, 20 May 2017 15:34:45 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-75-generic; KDE/5.18.0; x86_64; ; ) |
Paul Eggert wrote:
> > What is the best practice here? Should -fsanitize=address only be activated
> > after configure has run? Or should all configure run tests be changed so
> > that they
> > free all allocated memory?
>
> ... This is partly why we advise people not to run 'configure'
> with -Werror
This argument is not very convincing: With -Werror, we would need to deal
with all possible gcc warnings (there are many warning options) on all
supported platforms (there are many). This is impossible to handle.
Whereas here, memory leaks don't depend on gcc options, nor on the platform.
And the issue with -Werror keeps reappearing.
In fact, you already started the elimination of memory leaks from all gnulib
configure tests a year ago:
2016-02-06 Paul Eggert <address@hidden>
misc: port better to gcc -fsanitize=address
Without these patches, ./configure CFLAGS='-fsanitize=address'
would compute incorrect values. This patch fixes some (but not all)
test failures with recent glibc, with this configuration.
Let me complete your work here.
2017-05-20 Bruno Haible <address@hidden>
Avoid wrong configure results with gcc -fsanitize=address.
This completes the work done on 2016-02-06 on this topic.
* m4/memmem.m4 (gl_FUNC_MEMMEM): Free allocated memory before returning.
* m4/getcwd.m4 (gl_FUNC_GETCWD_NULL): Likewise.
* m4/strcasestr.m4 (gl_FUNC_STRCASESTR): Likewise.
* m4/strstr.m4 (gl_FUNC_STRSTR): Likewise.
* m4/fopen.m4 (gl_FUNC_FOPEN): Close allocated FILE streams before
returning.
* m4/fflush.m4 (gl_FUNC_FFLUSH_STDIN): Likewise.
* m4/fpurge.m4 (gl_FUNC_FPURGE): Likewise.
* m4/ftello.m4 (gl_FUNC_FTELLO): Likewise.
* m4/rmdir-errno.m4 (gl_FUNC_RMDIR_NOTEMPTY): Likewise.
* m4/signbit.m4 (gl_FLOATTYPE_SIGN_LOCATION): Likewise.
* m4/ungetc.m4 (gl_FUNC_UNGETC_WORKS): Likewise.
* m4/getdelim.m4 (gl_FUNC_GETDELIM): Close allocated FILE streams and
free allocated memory before returning.
* m4/getline.m4 (gl_FUNC_GETLINE): Likewise.
* m4/d-ino.m4 (gl_CHECK_TYPE_STRUCT_DIRENT_D_INO): Close allocated DIR
objects before returning.
* m4/iconv.m4 (AM_ICONV_LINK): Close allocated iconv_t handles before
returning.
diff --git a/m4/d-ino.m4 b/m4/d-ino.m4
index 79731ca..65cd4d8 100644
--- a/m4/d-ino.m4
+++ b/m4/d-ino.m4
@@ -1,4 +1,4 @@
-# serial 15
+# serial 16
dnl From Jim Meyering.
dnl
@@ -29,11 +29,11 @@ AC_DEFUN([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO],
return 1;
e = readdir (dp);
if (! e)
- return 2;
+ { closedir (dp); return 2; }
if (lstat (e->d_name, &st) != 0)
- return 3;
+ { closedir (dp); return 3; }
if (e->d_ino != st.st_ino)
- return 4;
+ { closedir (dp); return 4; }
closedir (dp);
return 0;
]])],
diff --git a/m4/fflush.m4 b/m4/fflush.m4
index 1d1f1ba..7732234 100644
--- a/m4/fflush.m4
+++ b/m4/fflush.m4
@@ -1,4 +1,4 @@
-# fflush.m4 serial 15
+# fflush.m4 serial 16
# Copyright (C) 2007-2017 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
@@ -44,16 +44,16 @@ AC_DEFUN([gl_FUNC_FFLUSH_STDIN],
return 1;
fd = fileno (f);
if (fd < 0 || fread (buffer, 1, 5, f) != 5)
- return 2;
+ { fclose (f); return 2; }
/* For deterministic results, ensure f read a bigger buffer. */
if (lseek (fd, 0, SEEK_CUR) == 5)
- return 3;
+ { fclose (f); return 3; }
/* POSIX requires fflush-fseek to set file offset of fd. This fails
on BSD systems and on mingw. */
if (fflush (f) != 0 || fseek (f, 0, SEEK_CUR) != 0)
- return 4;
+ { fclose (f); return 4; }
if (lseek (fd, 0, SEEK_CUR) != 5)
- return 5;
+ { fclose (f); return 5; }
/* Verify behaviour of fflush after ungetc. See
<http://www.opengroup.org/austin/aardvark/latest/xshbug3.txt> */
/* Verify behaviour of fflush after a backup ungetc. This fails on
@@ -62,14 +62,15 @@ AC_DEFUN([gl_FUNC_FFLUSH_STDIN],
ungetc (c, f);
fflush (f);
if (fgetc (f) != c)
- return 6;
+ { fclose (f); return 6; }
/* Verify behaviour of fflush after a non-backup ungetc. This fails
on glibc 2.8 and on BSD systems. */
c = fgetc (f);
ungetc ('@', f);
fflush (f);
if (fgetc (f) != c)
- return 7;
+ { fclose (f); return 7; }
+ fclose (f);
return 0;
]])], [gl_cv_func_fflush_stdin=yes], [gl_cv_func_fflush_stdin=no],
[gl_cv_func_fflush_stdin=cross])
diff --git a/m4/fopen.m4 b/m4/fopen.m4
index 0d09e4e..3772e50 100644
--- a/m4/fopen.m4
+++ b/m4/fopen.m4
@@ -1,4 +1,4 @@
-# fopen.m4 serial 9
+# fopen.m4 serial 10
dnl Copyright (C) 2007-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -27,7 +27,11 @@ AC_DEFUN([gl_FUNC_FOPEN],
#include <stdio.h>
int main ()
{
- return fopen ("conftest.sl/", "w") != NULL;
+ FILE *fp = fopen ("conftest.sl/", "w");
+ int result = (fp != NULL);
+ if (fp != NULL)
+ fclose (fp);
+ return result;
}]])],
[gl_cv_func_fopen_slash=yes],
[gl_cv_func_fopen_slash=no],
diff --git a/m4/fpurge.m4 b/m4/fpurge.m4
index 57be1b9..3533f4b 100644
--- a/m4/fpurge.m4
+++ b/m4/fpurge.m4
@@ -1,4 +1,4 @@
-# fpurge.m4 serial 7
+# fpurge.m4 serial 8
dnl Copyright (C) 2007, 2009-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -14,23 +14,40 @@ AC_DEFUN([gl_FUNC_FPURGE],
HAVE_FPURGE=1
# Detect BSD bug. Only cygwin 1.7 is known to be immune.
AC_CACHE_CHECK([whether fpurge works], [gl_cv_func_fpurge_works],
- [AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
-]], [FILE *f = fopen ("conftest.txt", "w+");
- if (!f) return 1;
- if (fputc ('a', f) != 'a') return 2;
- rewind (f);
- if (fgetc (f) != 'a') return 3;
- if (fgetc (f) != EOF) return 4;
- if (fpurge (f) != 0) return 5;
- if (putc ('b', f) != 'b') return 6;
- if (fclose (f) != 0) return 7;
- if ((f = fopen ("conftest.txt", "r")) == NULL) return 8;
- if (fgetc (f) != 'a') return 9;
- if (fgetc (f) != 'b') return 10;
- if (fgetc (f) != EOF) return 11;
- if (fclose (f) != 0) return 12;
- if (remove ("conftest.txt") != 0) return 13;
- return 0;])],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdio.h>
+]],
+ [FILE *f = fopen ("conftest.txt", "w+");
+ if (!f)
+ return 1;
+ if (fputc ('a', f) != 'a')
+ { fclose (f); return 2; }
+ rewind (f);
+ if (fgetc (f) != 'a')
+ { fclose (f); return 3; }
+ if (fgetc (f) != EOF)
+ { fclose (f); return 4; }
+ if (fpurge (f) != 0)
+ { fclose (f); return 5; }
+ if (putc ('b', f) != 'b')
+ { fclose (f); return 6; }
+ if (fclose (f) != 0)
+ return 7;
+ if ((f = fopen ("conftest.txt", "r")) == NULL)
+ return 8;
+ if (fgetc (f) != 'a')
+ { fclose (f); return 9; }
+ if (fgetc (f) != 'b')
+ { fclose (f); return 10; }
+ if (fgetc (f) != EOF)
+ { fclose (f); return 11; }
+ if (fclose (f) != 0)
+ return 12;
+ if (remove ("conftest.txt") != 0)
+ return 13;
+ return 0;
+ ])],
[gl_cv_func_fpurge_works=yes], [gl_cv_func_fpurge_works=no],
[gl_cv_func_fpurge_works='guessing no'])])
if test "x$gl_cv_func_fpurge_works" != xyes; then
diff --git a/m4/ftello.m4 b/m4/ftello.m4
index 0867c2a..8a4cdc5 100644
--- a/m4/ftello.m4
+++ b/m4/ftello.m4
@@ -1,4 +1,4 @@
-# ftello.m4 serial 11
+# ftello.m4 serial 12
dnl Copyright (C) 2007-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -73,7 +73,7 @@ main (void)
if (fp == NULL)
return 70;
if (fwrite ("foogarsh", 1, 8, fp) < 8)
- return 71;
+ { fclose (fp); return 71; }
if (fclose (fp))
return 72;
@@ -84,19 +84,19 @@ main (void)
if (fp == NULL)
return 73;
if (fseek (fp, -1, SEEK_END))
- return 74;
+ { fclose (fp); return 74; }
if (!(getc (fp) == 'h'))
- return 1;
+ { fclose (fp); return 1; }
if (!(getc (fp) == EOF))
- return 2;
+ { fclose (fp); return 2; }
if (!(ftell (fp) == 8))
- return 3;
+ { fclose (fp); return 3; }
if (!(ftell (fp) == 8))
- return 4;
+ { fclose (fp); return 4; }
if (!(putc ('!', fp) == '!'))
- return 5;
+ { fclose (fp); return 5; }
if (!(ftell (fp) == 9))
- return 6;
+ { fclose (fp); return 6; }
if (!(fclose (fp) == 0))
return 7;
fp = fopen (TESTFILE, "r");
@@ -105,9 +105,9 @@ main (void)
{
char buf[10];
if (!(fread (buf, 1, 10, fp) == 9))
- return 10;
+ { fclose (fp); return 10; }
if (!(memcmp (buf, "foogarsh!", 9) == 0))
- return 11;
+ { fclose (fp); return 11; }
}
if (!(fclose (fp) == 0))
return 12;
diff --git a/m4/getcwd.m4 b/m4/getcwd.m4
index ec6b637..a3f62c4 100644
--- a/m4/getcwd.m4
+++ b/m4/getcwd.m4
@@ -6,7 +6,7 @@
# with or without modifications, as long as this notice is preserved.
# Written by Paul Eggert.
-# serial 13
+# serial 14
AC_DEFUN([gl_FUNC_GETCWD_NULL],
[
@@ -37,9 +37,9 @@ AC_DEFUN([gl_FUNC_GETCWD_NULL],
if (! f)
return 2;
if (f[0] != '/')
- return 3;
+ { free (f); return 3; }
if (f[1] != '\0')
- return 4;
+ { free (f); return 4; }
free (f);
return 0;
}
diff --git a/m4/getdelim.m4 b/m4/getdelim.m4
index 24adb94..67afdba 100644
--- a/m4/getdelim.m4
+++ b/m4/getdelim.m4
@@ -1,4 +1,4 @@
-# getdelim.m4 serial 11
+# getdelim.m4 serial 12
dnl Copyright (C) 2005-2007, 2009-2017 Free Software Foundation, Inc.
dnl
@@ -39,7 +39,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
size_t siz = 0;
int len = getdelim (&line, &siz, '\n', in);
if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
- return 2;
+ { free (line); fclose (in); return 2; }
}
{
/* Test result for a NULL buffer and a non-zero size.
@@ -47,7 +47,7 @@ AC_DEFUN([gl_FUNC_GETDELIM],
char *line = NULL;
size_t siz = (size_t)(~0) / 4;
if (getdelim (&line, &siz, '\n', in) == -1)
- return 3;
+ { fclose (in); return 3; }
free (line);
}
fclose (in);
diff --git a/m4/getline.m4 b/m4/getline.m4
index dcea772..bd91bef 100644
--- a/m4/getline.m4
+++ b/m4/getline.m4
@@ -1,4 +1,4 @@
-# getline.m4 serial 27
+# getline.m4 serial 28
dnl Copyright (C) 1998-2003, 2005-2007, 2009-2017 Free Software Foundation,
dnl Inc.
@@ -46,7 +46,7 @@ AC_DEFUN([gl_FUNC_GETLINE],
size_t siz = 0;
int len = getline (&line, &siz, in);
if (!(len == 4 && line && strcmp (line, "foo\n") == 0))
- return 2;
+ { free (line); fclose (in); return 2; }
free (line);
}
{
@@ -55,7 +55,7 @@ AC_DEFUN([gl_FUNC_GETLINE],
char *line = NULL;
size_t siz = (size_t)(~0) / 4;
if (getline (&line, &siz, in) == -1)
- return 3;
+ { fclose (in); return 3; }
free (line);
}
fclose (in);
diff --git a/m4/iconv.m4 b/m4/iconv.m4
index bdafc54..81ac1a6 100644
--- a/m4/iconv.m4
+++ b/m4/iconv.m4
@@ -1,4 +1,4 @@
-# iconv.m4 serial 20
+# iconv.m4 serial 21
dnl Copyright (C) 2000-2002, 2007-2014, 2016 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -167,15 +167,27 @@ AC_DEFUN([AM_ICONV_LINK],
#endif
/* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
provided. */
- if (/* Try standardized names. */
- iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
- /* Try IRIX, OSF/1 names. */
- && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
- /* Try AIX names. */
- && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
- /* Try HP-UX names. */
- && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
- result |= 16;
+ {
+ /* Try standardized names. */
+ iconv_t cd1 = iconv_open ("UTF-8", "EUC-JP");
+ /* Try IRIX, OSF/1 names. */
+ iconv_t cd2 = iconv_open ("UTF-8", "eucJP");
+ /* Try AIX names. */
+ iconv_t cd3 = iconv_open ("UTF-8", "IBM-eucJP");
+ /* Try HP-UX names. */
+ iconv_t cd4 = iconv_open ("utf8", "eucJP");
+ if (cd1 == (iconv_t)(-1) && cd2 == (iconv_t)(-1)
+ && cd3 == (iconv_t)(-1) && cd4 == (iconv_t)(-1))
+ result |= 16;
+ if (cd1 != (iconv_t)(-1))
+ iconv_close (cd1);
+ if (cd2 != (iconv_t)(-1))
+ iconv_close (cd2);
+ if (cd3 != (iconv_t)(-1))
+ iconv_close (cd3);
+ if (cd4 != (iconv_t)(-1))
+ iconv_close (cd4);
+ }
return result;
]])],
[am_cv_func_iconv_works=yes], ,
diff --git a/m4/memmem.m4 b/m4/memmem.m4
index 9ef4dd4..334cb66 100644
--- a/m4/memmem.m4
+++ b/m4/memmem.m4
@@ -1,4 +1,4 @@
-# memmem.m4 serial 24
+# memmem.m4 serial 25
dnl Copyright (C) 2002-2004, 2007-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -113,6 +113,9 @@ static void quit (int sig) { _exit (sig + 128); }
if (!memmem (haystack, 2 * m + 1, needle, m + 1))
result |= 1;
}
+ /* Free allocated memory, in case some sanitizer is watching. */
+ free (haystack);
+ free (needle);
return result;
]])],
[gl_cv_func_memmem_works_fast=yes], [gl_cv_func_memmem_works_fast=no],
diff --git a/m4/rmdir-errno.m4 b/m4/rmdir-errno.m4
index c290a48..a389329 100644
--- a/m4/rmdir-errno.m4
+++ b/m4/rmdir-errno.m4
@@ -1,4 +1,4 @@
-# serial 10
+# serial 11
# Copyright (C) 2000-2001, 2005-2006, 2009-2017 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
@@ -33,6 +33,7 @@ AC_DEFUN([gl_FUNC_RMDIR_NOTEMPTY],
val = errno;
s = fopen ("confdir2/errno", "w");
fprintf (s, "%d\n", val);
+ fclose (s);
return 0;
}
]])],
diff --git a/m4/signbit.m4 b/m4/signbit.m4
index 9d2b0a8..f387ee9 100644
--- a/m4/signbit.m4
+++ b/m4/signbit.m4
@@ -1,4 +1,4 @@
-# signbit.m4 serial 13
+# signbit.m4 serial 14
dnl Copyright (C) 2007-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -272,6 +272,7 @@ int main ()
{
/* More than one bit difference. */
fprintf (fp, "unknown");
+ fclose (fp);
return 2;
}
if (x)
@@ -284,6 +285,7 @@ int main ()
{
/* No difference. */
fprintf (fp, "unknown");
+ fclose (fp);
return 3;
}
/* Now m = plus.word[k] ^ ~minus.word[k]. */
@@ -292,6 +294,7 @@ int main ()
/* Oh? The sign bit is set in the positive and cleared in the negative
numbers? */
fprintf (fp, "unknown");
+ fclose (fp);
return 4;
}
for (i = 0; ; i++)
diff --git a/m4/strcasestr.m4 b/m4/strcasestr.m4
index 7d15c65..3af9582 100644
--- a/m4/strcasestr.m4
+++ b/m4/strcasestr.m4
@@ -1,4 +1,4 @@
-# strcasestr.m4 serial 21
+# strcasestr.m4 serial 22
dnl Copyright (C) 2005, 2007-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -102,6 +102,9 @@ static void quit (int sig) { _exit (sig + 128); }
if (!strcasestr (haystack, needle))
result |= 1;
}
+ /* Free allocated memory, in case some sanitizer is watching. */
+ free (haystack);
+ free (needle);
return result;
]])],
[gl_cv_func_strcasestr_linear=yes], [gl_cv_func_strcasestr_linear=no],
diff --git a/m4/strstr.m4 b/m4/strstr.m4
index 9f7da64..4b472ee 100644
--- a/m4/strstr.m4
+++ b/m4/strstr.m4
@@ -1,4 +1,4 @@
-# strstr.m4 serial 17
+# strstr.m4 serial 18
dnl Copyright (C) 2008-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -99,6 +99,9 @@ static void quit (int sig) { _exit (sig + 128); }
if (!strstr (haystack, needle))
result |= 1;
}
+ /* Free allocated memory, in case some sanitizer is watching. */
+ free (haystack);
+ free (needle);
return result;
]])],
[gl_cv_func_strstr_linear=yes], [gl_cv_func_strstr_linear=no],
diff --git a/m4/ungetc.m4 b/m4/ungetc.m4
index 9fd3db9..72e8334 100644
--- a/m4/ungetc.m4
+++ b/m4/ungetc.m4
@@ -1,4 +1,4 @@
-# ungetc.m4 serial 3
+# ungetc.m4 serial 4
dnl Copyright (C) 2009-2017 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -14,19 +14,31 @@ AC_DEFUN_ONCE([gl_FUNC_UNGETC_WORKS],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#include <stdio.h>
]], [FILE *f;
- if (!(f = fopen ("conftest.tmp", "w+"))) return 1;
- if (fputs ("abc", f) < 0) return 2;
+ if (!(f = fopen ("conftest.tmp", "w+")))
+ return 1;
+ if (fputs ("abc", f) < 0)
+ { fclose (f); return 2; }
rewind (f);
- if (fgetc (f) != 'a') return 3;
- if (fgetc (f) != 'b') return 4;
- if (ungetc ('d', f) != 'd') return 5;
- if (ftell (f) != 1) return 6;
- if (fgetc (f) != 'd') return 7;
- if (ftell (f) != 2) return 8;
- if (fseek (f, 0, SEEK_CUR) != 0) return 9;
- if (ftell (f) != 2) return 10;
- if (fgetc (f) != 'c') return 11;
- fclose (f); remove ("conftest.tmp");])],
+ if (fgetc (f) != 'a')
+ { fclose (f); return 3; }
+ if (fgetc (f) != 'b')
+ { fclose (f); return 4; }
+ if (ungetc ('d', f) != 'd')
+ { fclose (f); return 5; }
+ if (ftell (f) != 1)
+ { fclose (f); return 6; }
+ if (fgetc (f) != 'd')
+ { fclose (f); return 7; }
+ if (ftell (f) != 2)
+ { fclose (f); return 8; }
+ if (fseek (f, 0, SEEK_CUR) != 0)
+ { fclose (f); return 9; }
+ if (ftell (f) != 2)
+ { fclose (f); return 10; }
+ if (fgetc (f) != 'c')
+ { fclose (f); return 11; }
+ fclose (f);
+ remove ("conftest.tmp");])],
[gl_cv_func_ungetc_works=yes], [gl_cv_func_ungetc_works=no],
[case "$host_os" in
# Guess yes on glibc and bionic systems.