]> Savannah Git Hosting - gnulib.git/commitdiff
stdio: Improve GCC 11 allocation-deallocation checking.
authorBruno Haible <bruno@clisp.org>
Sat, 7 Aug 2021 16:17:55 +0000 (18:17 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 7 Aug 2021 16:17:55 +0000 (18:17 +0200)
* lib/stdio.in.h (fdopen, fopen, tmpfile): Declare that deallocation
must happen through 'fclose'.
(popen): Declare that deallocation must happen through 'pclose'.
* lib/stdio-safer.h (fopen_safer, tmpfile_safer): Declare that
deallocation must happen through 'fclose'.
(popen_safer): Declare that deallocation must happen through 'pclose'.
(freopen_safer): Declare that arguments must be non-NULL.

ChangeLog
lib/stdio-safer.h
lib/stdio.in.h

index fbfa848a9b210883317dae7b670b8b79f2919552..1ef6f6b34cf92e4933e38337cb783072de395f16 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,19 @@
+2021-08-07  Bruno Haible  <bruno@clisp.org>
+
+       stdio: Improve GCC 11 allocation-deallocation checking.
+       * lib/stdio.in.h (fdopen, fopen, tmpfile): Declare that deallocation
+       must happen through 'fclose'.
+       (popen): Declare that deallocation must happen through 'pclose'.
+       * lib/stdio-safer.h (fopen_safer, tmpfile_safer): Declare that
+       deallocation must happen through 'fclose'.
+       (popen_safer): Declare that deallocation must happen through 'pclose'.
+       (freopen_safer): Declare that arguments must be non-NULL.
+
 2021-08-07  Bruno Haible  <bruno@clisp.org>
 
        dirent: Improve GCC 11 allocation-deallocation checking.
        * lib/dirent.in.h (closedir): Move declaration up.
-       (opendir, fdopendir): Declare that that deallocation must happen through
+       (opendir, fdopendir): Declare that deallocation must happen through
        'closedir'.
        * lib/dirent-safer.h (opendir_safer): Likewise.
        * lib/opendirat.h (opendirat): Likewise.
index 464ffcf933d1092c765793d9dad8d185fe1ef2d9..53ee971b47bd0f3a2617fb8524a84e5599ae9a55 100644 (file)
 #include <stdio.h>
 
 #if GNULIB_FOPEN_SAFER
-FILE *fopen_safer (char const *, char const *);
+FILE *fopen_safer (char const *, char const *)
+  _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1);
 #endif
 
 #if GNULIB_FREOPEN_SAFER
-FILE *freopen_safer (char const *, char const *, FILE *);
+FILE *freopen_safer (char const *, char const *, FILE *)
+  _GL_ARG_NONNULL ((2, 3));
 #endif
 
 #if GNULIB_POPEN_SAFER
-FILE *popen_safer (char const *, char const *);
+FILE *popen_safer (char const *, char const *)
+  _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1);
 #endif
 
 #if GNULIB_TMPFILE_SAFER
-FILE *tmpfile_safer (void);
+FILE *tmpfile_safer (void)
+  _GL_ATTRIBUTE_DEALLOC (fclose, 1);
 #endif
index 20ba488a4760f60b65a0a385fc9195dbdf5dc751..7986f72d107815d975aac966fb1a1384dd81908c 100644 (file)
@@ -260,8 +260,9 @@ _GL_CXXALIASWARN (fcloseall);
 #   undef fdopen
 #   define fdopen rpl_fdopen
 #  endif
-_GL_FUNCDECL_RPL (fdopen, FILE *, (int fd, const char *mode)
-                                  _GL_ARG_NONNULL ((2)));
+_GL_FUNCDECL_RPL (fdopen, FILE *,
+                  (int fd, const char *mode)
+                  _GL_ARG_NONNULL ((2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
 _GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode));
 # elif defined _WIN32 && !defined __CYGWIN__
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -380,7 +381,7 @@ _GL_CXXALIASWARN (fileno);
 #  endif
 _GL_FUNCDECL_RPL (fopen, FILE *,
                   (const char *restrict filename, const char *restrict mode)
-                  _GL_ARG_NONNULL ((1, 2)));
+                  _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (fclose, 1));
 _GL_CXXALIAS_RPL (fopen, FILE *,
                   (const char *restrict filename, const char *restrict mode));
 # else
@@ -1009,13 +1010,15 @@ _GL_WARN_ON_USE (perror, "perror is not always POSIX compliant - "
 #   undef popen
 #   define popen rpl_popen
 #  endif
-_GL_FUNCDECL_RPL (popen, FILE *, (const char *cmd, const char *mode)
-                                 _GL_ARG_NONNULL ((1, 2)));
+_GL_FUNCDECL_RPL (popen, FILE *,
+                  (const char *cmd, const char *mode)
+                  _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1));
 _GL_CXXALIAS_RPL (popen, FILE *, (const char *cmd, const char *mode));
 # else
 #  if !@HAVE_POPEN@
-_GL_FUNCDECL_SYS (popen, FILE *, (const char *cmd, const char *mode)
-                                 _GL_ARG_NONNULL ((1, 2)));
+_GL_FUNCDECL_SYS (popen, FILE *,
+                  (const char *cmd, const char *mode)
+                  _GL_ARG_NONNULL ((1, 2)) _GL_ATTRIBUTE_DEALLOC (pclose, 1));
 #  endif
 _GL_CXXALIAS_SYS (popen, FILE *, (const char *cmd, const char *mode));
 # endif
@@ -1346,7 +1349,8 @@ _GL_CXXALIASWARN (tempnam);
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   define tmpfile rpl_tmpfile
 #  endif
-_GL_FUNCDECL_RPL (tmpfile, FILE *, (void));
+_GL_FUNCDECL_RPL (tmpfile, FILE *, (void)
+                                   _GL_ATTRIBUTE_DEALLOC (fclose, 1));
 _GL_CXXALIAS_RPL (tmpfile, FILE *, (void));
 # else
 _GL_CXXALIAS_SYS (tmpfile, FILE *, (void));