]> Savannah Git Hosting - gnulib.git/commitdiff
dirent: Improve GCC 11 allocation-deallocation checking.
authorBruno Haible <bruno@clisp.org>
Sat, 7 Aug 2021 16:05:44 +0000 (18:05 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 7 Aug 2021 16:05:44 +0000 (18:05 +0200)
* lib/dirent.in.h (closedir): Move declaration up.
(opendir, fdopendir): Declare that that deallocation must happen through
'closedir'.
* lib/dirent-safer.h (opendir_safer): Likewise.
* lib/opendirat.h (opendirat): Likewise.

ChangeLog
lib/dirent-safer.h
lib/dirent.in.h
lib/opendirat.h

index c94dda2da3fba84b7cd29269d2ae967e23812767..fbfa848a9b210883317dae7b670b8b79f2919552 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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
+       'closedir'.
+       * lib/dirent-safer.h (opendir_safer): Likewise.
+       * lib/opendirat.h (opendirat): Likewise.
+
 2021-08-07  Bruno Haible  <bruno@clisp.org>
 
        stdlib, string, wchar: Improve GCC 11 allocation-deallocation checking.
index e18bb89d36eecd61fdc4651a23c771ab64c76502..70ada062ec1c4a72c9d7cea619d280c53d42b6ff 100644 (file)
@@ -23,7 +23,8 @@
 extern "C" {
 #endif
 
-DIR *opendir_safer (const char *name);
+DIR *opendir_safer (const char *name)
+  _GL_ATTRIBUTE_DEALLOC (closedir, 1);
 
 #ifdef __cplusplus
 }
index 647a3dba51c4c107f808b2993519a2c63c0938c4..49e0aa90eaf7cdb02cf263617298ec339d3c9e44 100644 (file)
@@ -74,6 +74,30 @@ typedef struct gl_directory DIR;
 
 /* Declare overridden functions.  */
 
+#if @GNULIB_CLOSEDIR@
+# if @REPLACE_CLOSEDIR@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef closedir
+#   define closedir rpl_closedir
+#   define GNULIB_defined_closedir 1
+#  endif
+_GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (closedir, int, (DIR *dirp));
+# else
+#  if !@HAVE_CLOSEDIR@
+_GL_FUNCDECL_SYS (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
+#  endif
+_GL_CXXALIAS_SYS (closedir, int, (DIR *dirp));
+# endif
+_GL_CXXALIASWARN (closedir);
+#elif defined GNULIB_POSIXCHECK
+# undef closedir
+# if HAVE_RAW_DECL_CLOSEDIR
+_GL_WARN_ON_USE (closedir, "closedir is not portable - "
+                 "use gnulib module closedir for portability");
+# endif
+#endif
+
 #if @GNULIB_OPENDIR@
 # if @REPLACE_OPENDIR@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -81,11 +105,17 @@ typedef struct gl_directory DIR;
 #   define opendir rpl_opendir
 #   define GNULIB_defined_opendir 1
 #  endif
-_GL_FUNCDECL_RPL (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)));
+_GL_FUNCDECL_RPL (opendir, DIR *,
+                  (const char *dir_name)
+                  _GL_ARG_NONNULL ((1))
+                  _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
 _GL_CXXALIAS_RPL (opendir, DIR *, (const char *dir_name));
 # else
 #  if !@HAVE_OPENDIR@
-_GL_FUNCDECL_SYS (opendir, DIR *, (const char *dir_name) _GL_ARG_NONNULL ((1)));
+_GL_FUNCDECL_SYS (opendir, DIR *,
+                  (const char *dir_name)
+                  _GL_ARG_NONNULL ((1))
+                  _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
 #  endif
 _GL_CXXALIAS_SYS (opendir, DIR *, (const char *dir_name));
 # endif
@@ -126,30 +156,6 @@ _GL_WARN_ON_USE (rewinddir, "rewinddir is not portable - "
 # endif
 #endif
 
-#if @GNULIB_CLOSEDIR@
-# if @REPLACE_CLOSEDIR@
-#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#   undef closedir
-#   define closedir rpl_closedir
-#   define GNULIB_defined_closedir 1
-#  endif
-_GL_FUNCDECL_RPL (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
-_GL_CXXALIAS_RPL (closedir, int, (DIR *dirp));
-# else
-#  if !@HAVE_CLOSEDIR@
-_GL_FUNCDECL_SYS (closedir, int, (DIR *dirp) _GL_ARG_NONNULL ((1)));
-#  endif
-_GL_CXXALIAS_SYS (closedir, int, (DIR *dirp));
-# endif
-_GL_CXXALIASWARN (closedir);
-#elif defined GNULIB_POSIXCHECK
-# undef closedir
-# if HAVE_RAW_DECL_CLOSEDIR
-_GL_WARN_ON_USE (closedir, "closedir is not portable - "
-                 "use gnulib module closedir for portability");
-# endif
-#endif
-
 #if @GNULIB_DIRFD@
 /* Return the file descriptor associated with the given directory stream,
    or -1 if none exists.  */
@@ -200,11 +206,15 @@ _GL_WARN_ON_USE (dirfd, "dirfd is unportable - "
 #   undef fdopendir
 #   define fdopendir rpl_fdopendir
 #  endif
-_GL_FUNCDECL_RPL (fdopendir, DIR *, (int fd));
+_GL_FUNCDECL_RPL (fdopendir, DIR *,
+                  (int fd)
+                  _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
 _GL_CXXALIAS_RPL (fdopendir, DIR *, (int fd));
 # else
 #  if !@HAVE_FDOPENDIR@ || !@HAVE_DECL_FDOPENDIR@
-_GL_FUNCDECL_SYS (fdopendir, DIR *, (int fd));
+_GL_FUNCDECL_SYS (fdopendir, DIR *,
+                  (int fd)
+                  _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1));
 #  endif
 _GL_CXXALIAS_SYS (fdopendir, DIR *, (int fd));
 # endif
index 845cc552f489f36a1ef843376ccb68e2a539f7b2..9765615b680ae0e89c6b74be92c7fb6df3ae9843 100644 (file)
@@ -17,4 +17,5 @@
 
 #include <dirent.h>
 
-DIR *opendirat (int, char const *, int, int *);
+DIR *opendirat (int, char const *, int, int *)
+  _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (closedir, 1);