From: Paul Eggert Date: Thu, 25 Mar 2021 19:41:41 +0000 (-0700) Subject: free-posix: use more often in other modules X-Git-Tag: v1.0~3003 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=5b3a6f94f866b02761105b55dfdfad4379a640bf;p=gnulib.git free-posix: use more often in other modules This lets us simplify cleanup code that calls ‘free’. * lib/amemxfrm.c (amemxfrm): * lib/areadlink-with-size.c (areadlink_with_size): * lib/areadlinkat-with-size.c (areadlinkat_with_size): * lib/astrxfrm.c (astrxfrm): * lib/dprintf.c (dprintf): * lib/execute.c (execute): * lib/execvpe.c (execvpe): * lib/fchdir.c (get_name): * lib/file-has-acl.c (file_has_acl): * lib/fprintf.c (fprintf): * lib/getcwd-lgpl.c (rpl_getcwd): * lib/getgroups.c (rpl_getgroups): * lib/link.c (link, rpl_link): * lib/linkat.c (link_immediate, link_follow, linkat_follow): * lib/localename.c (newlocale, duplocale): * lib/mgetgroups.c (mgetgroups): * lib/mountlist.c (read_file_system_list): * lib/pipe-filter-gi.c (pipe_filter_gi_close): * lib/putenv.c (_unsetenv, putenv): * lib/read-file.c (read_file): * lib/rename.c (rpl_rename): * lib/savedir.c (streamsavedir, savedir): * lib/spawni.c (do_open, __spawni): * lib/spawn-pipe.c (create_pipe): * lib/striconv.c (mem_cd_iconv, str_cd_iconv, str_iconv): * lib/striconveh.c (mem_cd_iconveh_internal, str_cd_iconveh) (mem_iconveh, str_iconveh): * lib/supersede.c (open_supersede, close_supersede): * lib/vasnprintf.c (VASNPRINTF): * lib/vdprintf.c (vdprintf): * lib/vfprintf.c (vfprintf): * lib/wcscoll-impl.h (wcscoll): * lib/wcsxfrm-impl.h (wcsxfrm): * lib/xgetdomainname.c (xgetdomainname): * lib/xgethostname.c (xgethostname): Simplify by assuming that ‘free’ preserves errno. * lib/localename.c: Do not include errno.h. * modules/amemxfrm, modules/areadlink-with-size: * modules/areadlinkat-with-size, modules/astrxfrm: * modules/c-vasnprintf, modules/dprintf, modules/execute: * modules/execvpe, modules/fchdir, modules/file-has-acl: * modules/fprintf-posix, modules/getcwd-lgpl, modules/getgroups: * modules/link, modules/linkat, modules/localename: * modules/mgetgroups, modules/mountlist, modules/pipe-filter-gi: * modules/posix_spawn-internal, modules/putenv, modules/read-file: * modules/rename, modules/savedir, modules/spawn-pipe: * modules/striconv, modules/striconveh, modules/supersede: * modules/vasnprintf, modules/vdprintf, modules/vfprintf-posix: * modules/wcscoll, modules/wcsxfrm, modules/xgetdomainname: * modules/xgethostname: Depend on free-posix. --- diff --git a/ChangeLog b/ChangeLog index af9eb725cb..b9fb4b7979 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,59 @@ +2021-03-25 Paul Eggert + + free-posix: use more often in other modules + This lets us simplify cleanup code that calls ‘free’. + * lib/amemxfrm.c (amemxfrm): + * lib/areadlink-with-size.c (areadlink_with_size): + * lib/areadlinkat-with-size.c (areadlinkat_with_size): + * lib/astrxfrm.c (astrxfrm): + * lib/dprintf.c (dprintf): + * lib/execute.c (execute): + * lib/execvpe.c (execvpe): + * lib/fchdir.c (get_name): + * lib/file-has-acl.c (file_has_acl): + * lib/fprintf.c (fprintf): + * lib/getcwd-lgpl.c (rpl_getcwd): + * lib/getgroups.c (rpl_getgroups): + * lib/link.c (link, rpl_link): + * lib/linkat.c (link_immediate, link_follow, linkat_follow): + * lib/localename.c (newlocale, duplocale): + * lib/mgetgroups.c (mgetgroups): + * lib/mountlist.c (read_file_system_list): + * lib/pipe-filter-gi.c (pipe_filter_gi_close): + * lib/putenv.c (_unsetenv, putenv): + * lib/read-file.c (read_file): + * lib/rename.c (rpl_rename): + * lib/savedir.c (streamsavedir, savedir): + * lib/spawni.c (do_open, __spawni): + * lib/spawn-pipe.c (create_pipe): + * lib/striconv.c (mem_cd_iconv, str_cd_iconv, str_iconv): + * lib/striconveh.c (mem_cd_iconveh_internal, str_cd_iconveh) + (mem_iconveh, str_iconveh): + * lib/supersede.c (open_supersede, close_supersede): + * lib/vasnprintf.c (VASNPRINTF): + * lib/vdprintf.c (vdprintf): + * lib/vfprintf.c (vfprintf): + * lib/wcscoll-impl.h (wcscoll): + * lib/wcsxfrm-impl.h (wcsxfrm): + * lib/xgetdomainname.c (xgetdomainname): + * lib/xgethostname.c (xgethostname): + Simplify by assuming that ‘free’ preserves errno. + * lib/localename.c: Do not include errno.h. + * modules/amemxfrm, modules/areadlink-with-size: + * modules/areadlinkat-with-size, modules/astrxfrm: + * modules/c-vasnprintf, modules/dprintf, modules/execute: + * modules/execvpe, modules/fchdir, modules/file-has-acl: + * modules/fprintf-posix, modules/getcwd-lgpl, modules/getgroups: + * modules/link, modules/linkat, modules/localename: + * modules/mgetgroups, modules/mountlist, modules/pipe-filter-gi: + * modules/posix_spawn-internal, modules/putenv, modules/read-file: + * modules/rename, modules/savedir, modules/spawn-pipe: + * modules/striconv, modules/striconveh, modules/supersede: + * modules/vasnprintf, modules/vdprintf, modules/vfprintf-posix: + * modules/wcscoll, modules/wcsxfrm, modules/xgetdomainname: + * modules/xgethostname: + Depend on free-posix. + 2021-03-24 Paul Eggert renameatu: work around macOS 11.2 renameatx_np bug diff --git a/lib/amemxfrm.c b/lib/amemxfrm.c index 44a6cf9f0d..ab78b4a15f 100644 --- a/lib/amemxfrm.c +++ b/lib/amemxfrm.c @@ -161,14 +161,10 @@ amemxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp) return result; fail: - { - int saved_errno = errno; - if (result != resultbuf) - free (result); - s[n] = orig_sentinel; - errno = saved_errno; - return NULL; - } + if (result != resultbuf) + free (result); + s[n] = orig_sentinel; + return NULL; out_of_memory_1: if (result != resultbuf) diff --git a/lib/areadlink-with-size.c b/lib/areadlink-with-size.c index 79f253255f..28a1d553cf 100644 --- a/lib/areadlink-with-size.c +++ b/lib/areadlink-with-size.c @@ -90,9 +90,7 @@ areadlink_with_size (char const *file, size_t size) if (r < 0) { - int saved_errno = errno; free (buffer); - errno = saved_errno; return NULL; } diff --git a/lib/areadlinkat-with-size.c b/lib/areadlinkat-with-size.c index 12e81ac2f0..05156ac231 100644 --- a/lib/areadlinkat-with-size.c +++ b/lib/areadlinkat-with-size.c @@ -94,9 +94,7 @@ areadlinkat_with_size (int fd, char const *file, size_t size) if (r < 0) { - int saved_errno = errno; free (buffer); - errno = saved_errno; return NULL; } diff --git a/lib/astrxfrm.c b/lib/astrxfrm.c index 43ea98d8b2..2a6e3022dd 100644 --- a/lib/astrxfrm.c +++ b/lib/astrxfrm.c @@ -167,13 +167,9 @@ astrxfrm (const char *s, char *resultbuf, size_t *lengthp) return result; fail: - { - int saved_errno = errno; - if (result != resultbuf && result != tmpbuf) - free (result); - errno = saved_errno; - return NULL; - } + if (result != resultbuf && result != tmpbuf) + free (result); + return NULL; out_of_memory: errno = ENOMEM; diff --git a/lib/dprintf.c b/lib/dprintf.c index 9cf562f893..2926e87cd2 100644 --- a/lib/dprintf.c +++ b/lib/dprintf.c @@ -49,11 +49,7 @@ dprintf (int fd, const char *format, ...) if (full_write (fd, output, len) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + free (output); return -1; } diff --git a/lib/execute.c b/lib/execute.c index 1e8c8aa247..472b171200 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -156,9 +156,8 @@ execute (const char *progname, CAN_MISSING | CAN_NOLINKS); if (absolute_prog == NULL) { - saved_errno = errno; free (prog_path_to_free); - goto fail_with_saved_errno; + goto fail_with_errno; } free (prog_path_to_free); prog_path_to_free = absolute_prog; diff --git a/lib/execvpe.c b/lib/execvpe.c index ad745ea0e6..71eeb20836 100644 --- a/lib/execvpe.c +++ b/lib/execvpe.c @@ -54,10 +54,6 @@ execvpe (const char *program, char * const *argv, char * const *env) /* If execve returned, it must have failed. */ if (resolved_progname != program) - { - int saved_errno = errno; - free ((char *) resolved_progname); - errno = saved_errno; - } + free ((char *) resolved_progname); return -1; } diff --git a/lib/fchdir.c b/lib/fchdir.c index c6294cb9ed..d909b29a5c 100644 --- a/lib/fchdir.c +++ b/lib/fchdir.c @@ -91,7 +91,6 @@ get_name (char const *dir) { char *cwd; char *result; - int saved_errno; if (IS_ABSOLUTE_FILE_NAME (dir)) return strdup (dir); @@ -102,9 +101,7 @@ get_name (char const *dir) return cwd; result = mfile_name_concat (cwd, dir, NULL); - saved_errno = errno; free (cwd); - errno = saved_errno; return result; } diff --git a/lib/file-has-acl.c b/lib/file-has-acl.c index eb57c24d0b..800af227cc 100644 --- a/lib/file-has-acl.c +++ b/lib/file-has-acl.c @@ -206,9 +206,7 @@ file_has_acl (char const *name, struct stat const *sb) ; else { - int saved_errno = errno; free (malloced); - errno = saved_errno; return -1; } } @@ -281,9 +279,7 @@ file_has_acl (char const *name, struct stat const *sb) ; else { - int saved_errno = errno; free (malloced); - errno = saved_errno; return -1; } } @@ -418,11 +414,7 @@ file_has_acl (char const *name, struct stat const *sb) if (errno != ENOSPC) { if (acl != aclbuf) - { - int saved_errno = errno; - free (acl); - errno = saved_errno; - } + free (acl); return -1; } aclsize = 2 * aclsize; diff --git a/lib/fprintf.c b/lib/fprintf.c index 86a30c6396..3030c8f5e8 100644 --- a/lib/fprintf.c +++ b/lib/fprintf.c @@ -55,11 +55,7 @@ fprintf (FILE *fp, const char *format, ...) if (fwrite (output, 1, len, fp) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + free (output); return -1; } diff --git a/lib/getcwd-lgpl.c b/lib/getcwd-lgpl.c index e8c9e08cb3..bfb33a80c0 100644 --- a/lib/getcwd-lgpl.c +++ b/lib/getcwd-lgpl.c @@ -69,11 +69,7 @@ rpl_getcwd (char *buf, size_t size) } result = getcwd (buf, size); if (!result) - { - int saved_errno = errno; - free (buf); - errno = saved_errno; - } + free (buf); return result; } @@ -112,11 +108,7 @@ rpl_getcwd (char *buf, size_t size) while (!result && errno == ERANGE); if (!result) - { - int saved_errno = errno; - free (buf); - errno = saved_errno; - } + free (buf); else { /* Here result == buf. */ diff --git a/lib/getgroups.c b/lib/getgroups.c index af602a74d3..8786726e7c 100644 --- a/lib/getgroups.c +++ b/lib/getgroups.c @@ -70,7 +70,6 @@ rpl_getgroups (int n, gid_t *group) { int n_groups; GETGROUPS_T *gbuf; - int saved_errno; if (n < 0) { @@ -99,9 +98,7 @@ rpl_getgroups (int n, gid_t *group) while (n--) group[n] = gbuf[n]; } - saved_errno = errno; free (gbuf); - errno = saved_errno; return result; } @@ -121,10 +118,7 @@ rpl_getgroups (int n, gid_t *group) n *= 2; } - saved_errno = errno; free (gbuf); - errno = saved_errno; - return n_groups; } diff --git a/lib/link.c b/lib/link.c index 21c7f7aed0..ed6db8d642 100644 --- a/lib/link.c +++ b/lib/link.c @@ -117,9 +117,7 @@ link (const char *file1, const char *file2) *p = '\0'; if (p != dir && stat (dir, &st) != 0 && errno != EOVERFLOW) { - int saved_errno = errno; free (dir); - errno = saved_errno; return -1; } free (dir); @@ -228,9 +226,7 @@ rpl_link (char const *file1, char const *file2) *p = '\0'; if (stat (dir, &st) != 0 && errno != EOVERFLOW) { - int saved_errno = errno; free (dir); - errno = saved_errno; return -1; } } diff --git a/lib/linkat.c b/lib/linkat.c index 6c1c54f327..d10d44be13 100644 --- a/lib/linkat.c +++ b/lib/linkat.c @@ -64,10 +64,8 @@ link_immediate (char const *file1, char const *file2) if (st1.st_dev == st2.st_dev) { int result = symlink (target, file2); - int saved_errno = errno; free (target); free (dir); - errno = saved_errno; return result; } free (target); @@ -137,20 +135,12 @@ link_follow (char const *file1, char const *file2) if (!target && errno != EINVAL) { if (name != file1) - { - int saved_errno = errno; - free (name); - errno = saved_errno; - } + free (name); return -1; } result = link (name, file2); if (name != file1) - { - int saved_errno = errno; - free (name); - errno = saved_errno; - } + free (name); return result; } # endif /* 0 < LINK_FOLLOWS_SYMLINKS */ @@ -261,20 +251,12 @@ linkat_follow (int fd1, char const *file1, int fd2, char const *file2) if (!target && errno != EINVAL) { if (name != file1) - { - int saved_errno = errno; - free (name); - errno = saved_errno; - } + free (name); return -1; } result = linkat (fd1, name, fd2, file2, 0); if (name != file1) - { - int saved_errno = errno; - free (name); - errno = saved_errno; - } + free (name); return result; } diff --git a/lib/localename.c b/lib/localename.c index 0e63da4d4b..d47dd2fc8b 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -58,7 +58,6 @@ extern char * getlocalename_l(int, locale_t); # endif # endif # if HAVE_NAMELESS_LOCALES -# include # include "localename-table.h" # endif #endif @@ -2930,9 +2929,7 @@ newlocale (int category_mask, const char *name, locale_t base) result = newlocale (category_mask, name, base); if (result == NULL) { - int saved_errno = errno; free (node); - errno = saved_errno; return NULL; } @@ -2991,9 +2988,7 @@ duplocale (locale_t locale) result = duplocale (locale); if (result == NULL) { - int saved_errno = errno; free (node); - errno = saved_errno; return NULL; } diff --git a/lib/mgetgroups.c b/lib/mgetgroups.c index f226bc09cd..8570c910ce 100644 --- a/lib/mgetgroups.c +++ b/lib/mgetgroups.c @@ -102,9 +102,7 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups) if ((h = realloc_groupbuf (g, max_n_groups)) == NULL) { - int saved_errno = errno; free (g); - errno = saved_errno; return -1; } g = h; @@ -153,9 +151,7 @@ mgetgroups (char const *username, gid_t gid, gid_t **groups) if (ng < 0) { /* Failure is unexpected, but handle it anyway. */ - int saved_errno = errno; free (g); - errno = saved_errno; return -1; } diff --git a/lib/mountlist.c b/lib/mountlist.c index 27989d271c..f5d1364c1b 100644 --- a/lib/mountlist.c +++ b/lib/mountlist.c @@ -990,9 +990,7 @@ read_file_system_list (bool need_fs_type) n_entries = mntctl (MCTL_QUERY, bufsize, entries); if (n_entries < 0) { - int saved_errno = errno; free (entries); - errno = saved_errno; return NULL; } @@ -1109,7 +1107,8 @@ read_file_system_list (bool need_fs_type) /* Free a mount entry as returned from read_file_system_list (). */ -void free_mount_entry (struct mount_entry *me) +void +free_mount_entry (struct mount_entry *me) { free (me->me_devname); free (me->me_mountdir); diff --git a/lib/pipe-filter-gi.c b/lib/pipe-filter-gi.c index 04fc91cd80..b53726ea93 100644 --- a/lib/pipe-filter-gi.c +++ b/lib/pipe-filter-gi.c @@ -554,12 +554,9 @@ int pipe_filter_gi_close (struct pipe_filter_gi *filter) { int ret; - int saved_errno; filter_terminate (filter); ret = filter_retcode (filter); - saved_errno = errno; free (filter); - errno = saved_errno; return ret; } diff --git a/lib/putenv.c b/lib/putenv.c index a3f86c0e69..555474f4da 100644 --- a/lib/putenv.c +++ b/lib/putenv.c @@ -82,15 +82,13 @@ _unsetenv (const char *name) #if HAVE_DECL__PUTENV { - int putenv_result, putenv_errno; + int putenv_result; char *name_ = malloc (len + 2); memcpy (name_, name, len); name_[len] = '='; name_[len + 1] = 0; putenv_result = _putenv (name_); - putenv_errno = errno; free (name_); - __set_errno (putenv_errno); return putenv_result; } #else @@ -144,7 +142,7 @@ putenv (char *string) /* _putenv ("NAME=") unsets NAME, so invoke _putenv ("NAME= ") to allocate the environ vector and then replace the new entry with "NAME=". */ - int putenv_result, putenv_errno; + int putenv_result; char *name_x = malloc (name_end - string + sizeof "= "); if (!name_x) return -1; @@ -152,7 +150,6 @@ putenv (char *string) name_x[name_end - string + 1] = ' '; name_x[name_end - string + 2] = 0; putenv_result = _putenv (name_x); - putenv_errno = errno; for (ep = environ; *ep; ep++) if (strcmp (*ep, name_x) == 0) { @@ -166,11 +163,10 @@ putenv (char *string) fix that by calling SetEnvironmentVariable directly. */ name_x[name_end - string] = 0; putenv_result = SetEnvironmentVariable (name_x, "") ? 0 : -1; - putenv_errno = ENOMEM; /* ENOMEM is the only way to fail. */ + errno = ENOMEM; /* ENOMEM is the only way to fail. */ } # endif free (name_x); - __set_errno (putenv_errno); return putenv_result; } #else diff --git a/lib/read-file.c b/lib/read-file.c index 1033e5c909..1d2084db33 100644 --- a/lib/read-file.c +++ b/lib/read-file.c @@ -192,7 +192,6 @@ read_file (const char *filename, int flags, size_t *length) const char *mode = (flags & RF_BINARY) ? "rbe" : "re"; FILE *stream = fopen (filename, mode); char *out; - int save_errno; if (!stream) return NULL; @@ -202,18 +201,14 @@ read_file (const char *filename, int flags, size_t *length) out = fread_file (stream, flags, length); - save_errno = errno; - if (fclose (stream) != 0) { if (out) { - save_errno = errno; if (flags & RF_SENSITIVE) explicit_bzero (out, *length); free (out); } - errno = save_errno; return NULL; } diff --git a/lib/rename.c b/lib/rename.c index e0f417de69..7eae1c7353 100644 --- a/lib/rename.c +++ b/lib/rename.c @@ -165,10 +165,8 @@ rpl_rename (char const *src, char const *dst) } if (rmdir (dst)) { - error = errno; free (src_temp); free (dst_temp); - errno = error; return -1; } free (src_temp); diff --git a/lib/savedir.c b/lib/savedir.c index bf06597b90..bcf41700d2 100644 --- a/lib/savedir.c +++ b/lib/savedir.c @@ -96,7 +96,6 @@ streamsavedir (DIR *dirp, enum savedir_option option) size_t entries_allocated = 0; size_t entries_used = 0; size_t used = 0; - int readdir_errno; comparison_function cmp = comparison_function_table[option]; if (dirp == NULL) @@ -148,12 +147,10 @@ streamsavedir (DIR *dirp, enum savedir_option option) } } - readdir_errno = errno; - if (readdir_errno != 0) + if (errno != 0) { free (entries); free (name_space); - errno = readdir_errno; return NULL; } @@ -196,9 +193,7 @@ savedir (char const *dir, enum savedir_option option) char *name_space = streamsavedir (dirp, option); if (closedir (dirp) != 0) { - int closedir_errno = errno; free (name_space); - errno = closedir_errno; return NULL; } return name_space; diff --git a/lib/spawn-pipe.c b/lib/spawn-pipe.c index 0fe86ffe2c..cedd48ab2f 100644 --- a/lib/spawn-pipe.c +++ b/lib/spawn-pipe.c @@ -180,9 +180,8 @@ create_pipe (const char *progname, canonicalize_filename_mode (prog_path, CAN_MISSING | CAN_NOLINKS); if (absolute_prog == NULL) { - saved_errno = errno; free (prog_path_to_free); - goto fail_with_saved_errno; + goto fail_with_errno; } free (prog_path_to_free); prog_path_to_free = absolute_prog; diff --git a/lib/spawni.c b/lib/spawni.c index 17e32699d1..aad55f37fd 100644 --- a/lib/spawni.c +++ b/lib/spawni.c @@ -398,9 +398,7 @@ do_open (struct inheritable_handles *inh_handles, int newfd, HANDLE handle = open_handle (filename, flags, mode); if (handle == INVALID_HANDLE_VALUE) { - int saved_errno = errno; free (filename_to_free); - errno = saved_errno; return -1; } free (filename_to_free); @@ -711,13 +709,10 @@ __spawni (pid_t *pid, const char *prog_filename, } failed_1: - { - int saved_errno = errno; - free (envblock); - free (command); - free (argv_mem_to_free); - return saved_errno; - } + free (envblock); + free (command); + free (argv_mem_to_free); + return errno; } #else diff --git a/lib/striconv.c b/lib/striconv.c index ec07729b60..a8d9dc1151 100644 --- a/lib/striconv.c +++ b/lib/striconv.c @@ -193,11 +193,7 @@ mem_cd_iconv (const char *src, size_t srclen, iconv_t cd, fail: { if (result != *resultp) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + free (result); return -1; } # undef tmpbufsize @@ -385,12 +381,8 @@ str_cd_iconv (const char *src, iconv_t cd) return result; failed: - { - int saved_errno = errno; - free (result); - errno = saved_errno; - return NULL; - } + free (result); + return NULL; # endif } @@ -441,11 +433,7 @@ str_iconv (const char *src, const char *from_codeset, const char *to_codeset) { if (iconv_close (cd) < 0) { - /* Return NULL, but free the allocated memory, and while doing - that, preserve the errno from iconv_close. */ - int saved_errno = errno; free (result); - errno = saved_errno; return NULL; } } diff --git a/lib/striconveh.c b/lib/striconveh.c index d31d842ca1..6b0e38b8de 100644 --- a/lib/striconveh.c +++ b/lib/striconveh.c @@ -499,11 +499,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, else { if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + free (result); return -1; } } @@ -570,11 +566,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, else { if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + free (result); return -1; } } @@ -683,11 +675,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, && !(errno == E2BIG || errno == EINVAL || errno == EILSEQ)) { if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + free (result); return -1; } if (res1 == (size_t)(-1) @@ -907,22 +895,14 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, { /* Failure converting the ASCII replacement. */ if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + free (result); return -1; } } else { if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + free (result); return -1; } } @@ -1041,12 +1021,7 @@ str_cd_iconveh (const char *src, if (retval < 0) { - if (result != NULL) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + free (result); return NULL; } @@ -1118,12 +1093,8 @@ mem_iconveh (const char *src, size_t srclen, { if (iconveh_close (&cd) < 0) { - /* Return -1, but free the allocated memory, and while doing - that, preserve the errno from iconveh_close. */ - int saved_errno = errno; - if (result != *resultp && result != NULL) + if (result != *resultp) free (result); - errno = saved_errno; return -1; } *resultp = result; @@ -1177,11 +1148,7 @@ str_iconveh (const char *src, { if (iconveh_close (&cd) < 0) { - /* Return NULL, but free the allocated memory, and while doing - that, preserve the errno from iconveh_close. */ - int saved_errno = errno; free (result); - errno = saved_errno; return NULL; } } diff --git a/lib/supersede.c b/lib/supersede.c index 8364fca70f..7371e20e2b 100644 --- a/lib/supersede.c +++ b/lib/supersede.c @@ -122,11 +122,7 @@ open_supersede (const char *filename, int flags, mode_t mode, { fd = create_temp_file (canon_filename, flags, mode, action); if (fd < 0) - { - int saved_errno = errno; - free (canon_filename); - errno = saved_errno; - } + free (canon_filename); } } } @@ -169,29 +165,19 @@ open_supersede (const char *filename, int flags, mode_t mode, fd = create_temp_file (canon_filename, flags, mode, action); if (fd < 0) - { - int saved_errno = errno; - free (canon_filename); - errno = saved_errno; - } + free (canon_filename); } else { /* It is possibly a character device, socket, or something like that. */ fd = open (canon_filename, flags | extra_flags, mode); + free (canon_filename); if (fd >= 0) { - free (canon_filename); action->final_rename_temp = NULL; action->final_rename_dest = NULL; } - else - { - int saved_errno = errno; - free (canon_filename); - errno = saved_errno; - } } } } @@ -242,11 +228,7 @@ open_supersede (const char *filename, int flags, mode_t mode, { fd = create_temp_file (canon_filename, flags, mode, action); if (fd < 0) - { - int saved_errno = errno; - free (canon_filename); - errno = saved_errno; - } + free (canon_filename); } } } @@ -394,10 +376,8 @@ close_supersede (int fd, const struct supersede_final_action *action) { if (fd < 0) { - int saved_errno = errno; free (action->final_rename_temp); free (action->final_rename_dest); - errno = saved_errno; return fd; } diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 4db1f35ae9..3fc9be5611 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -2183,13 +2183,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, # endif if (converted == NULL) { - int saved_errno = errno; if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); - CLEANUP (); - errno = saved_errno; return NULL; } if (converted != result + length) @@ -3079,13 +3076,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, NULL, &tmpdst_len); if (tmpdst == NULL) { - int saved_errno = errno; if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); - errno = saved_errno; return NULL; } # endif @@ -5602,13 +5597,11 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, NULL, &tmpdst_len); if (tmpdst == NULL) { - int saved_errno = errno; if (!(result == resultbuf || result == NULL)) free (result); if (buf_malloced != NULL) free (buf_malloced); CLEANUP (); - errno = saved_errno; return NULL; } ENSURE_ALLOCATION (xsum (length, tmpdst_len)); diff --git a/lib/vdprintf.c b/lib/vdprintf.c index 45bcfb1e83..7665a5880e 100644 --- a/lib/vdprintf.c +++ b/lib/vdprintf.c @@ -46,11 +46,7 @@ vdprintf (int fd, const char *format, va_list args) if (full_write (fd, output, len) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + free (output); return -1; } diff --git a/lib/vfprintf.c b/lib/vfprintf.c index f095e6c27b..dcfc8ce43a 100644 --- a/lib/vfprintf.c +++ b/lib/vfprintf.c @@ -52,11 +52,7 @@ vfprintf (FILE *fp, const char *format, va_list args) if (fwrite (output, 1, len, fp) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + free (output); return -1; } diff --git a/lib/wcscoll-impl.h b/lib/wcscoll-impl.h index 74ecf562c6..1adcba75da 100644 --- a/lib/wcscoll-impl.h +++ b/lib/wcscoll-impl.h @@ -81,17 +81,9 @@ wcscoll (const wchar_t *s1, const wchar_t *s2) int result = strcoll (mbs1, mbs2); if (mbs1 != mbbuf1) - { - int saved_errno = errno; - free (mbs1); - errno = saved_errno; - } + free (mbs1); if (mbs2 != mbbuf2) - { - int saved_errno = errno; - free (mbs2); - errno = saved_errno; - } + free (mbs2); return result; } diff --git a/lib/wcsxfrm-impl.h b/lib/wcsxfrm-impl.h index 2377cb2acd..5374e4400f 100644 --- a/lib/wcsxfrm-impl.h +++ b/lib/wcsxfrm-impl.h @@ -55,11 +55,7 @@ wcsxfrm (wchar_t *s1, const wchar_t *s2, size_t n) { /* An error occurred. */ if (mbs2 != mbbuf2) - { - saved_errno = errno; - free (mbs2); - errno = saved_errno; - } + free (mbs2); return 0; } diff --git a/lib/xgetdomainname.c b/lib/xgetdomainname.c index c41a1d5ea2..d77c9b7040 100644 --- a/lib/xgetdomainname.c +++ b/lib/xgetdomainname.c @@ -67,9 +67,7 @@ xgetdomainname (void) break; else if (err < 0 && errno != EINVAL) { - int saved_errno = errno; free (domainname); - errno = saved_errno; return NULL; } size *= 2; diff --git a/lib/xgethostname.c b/lib/xgethostname.c index fe9114b76f..10e13de1d2 100644 --- a/lib/xgethostname.c +++ b/lib/xgethostname.c @@ -64,9 +64,7 @@ xgethostname (void) /* OSX/Darwin does this when the buffer is not large enough */ && errno != ENOMEM) { - int saved_errno = errno; free (hostname); - errno = saved_errno; return NULL; } } diff --git a/modules/amemxfrm b/modules/amemxfrm index cf48753639..c21b5f1a9e 100644 --- a/modules/amemxfrm +++ b/modules/amemxfrm @@ -6,6 +6,7 @@ lib/amemxfrm.h lib/amemxfrm.c Depends-on: +free-posix configure.ac: AC_REQUIRE([AC_C_RESTRICT]) diff --git a/modules/areadlink-with-size b/modules/areadlink-with-size index 82a902187e..40846425d2 100644 --- a/modules/areadlink-with-size +++ b/modules/areadlink-with-size @@ -6,6 +6,7 @@ lib/areadlink.h lib/areadlink-with-size.c Depends-on: +free-posix readlink ssize_t stdint diff --git a/modules/areadlinkat-with-size b/modules/areadlinkat-with-size index 51fb1a87ee..d66ba26ea4 100644 --- a/modules/areadlinkat-with-size +++ b/modules/areadlinkat-with-size @@ -16,6 +16,7 @@ extensions fchdir fcntl-h filename +free-posix openat-die openat-h save-cwd diff --git a/modules/astrxfrm b/modules/astrxfrm index 053340344c..5e16bf32bd 100644 --- a/modules/astrxfrm +++ b/modules/astrxfrm @@ -6,6 +6,7 @@ lib/astrxfrm.h lib/astrxfrm.c Depends-on: +free-posix configure.ac: AC_REQUIRE([AC_C_RESTRICT]) diff --git a/modules/c-vasnprintf b/modules/c-vasnprintf index 129f591d42..f193f70856 100644 --- a/modules/c-vasnprintf +++ b/modules/c-vasnprintf @@ -31,6 +31,7 @@ printf-frexp printf-frexpl signbit fpucw +free-posix nocrash printf-safe alloca-opt diff --git a/modules/dprintf b/modules/dprintf index 43838fffb5..653cb9380c 100644 --- a/modules/dprintf +++ b/modules/dprintf @@ -8,6 +8,7 @@ m4/dprintf.m4 Depends-on: stdio vasnprintf [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] +free-posix [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] full-write [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] errno [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] diff --git a/modules/execute b/modules/execute index 434558050e..fc90554ea4 100644 --- a/modules/execute +++ b/modules/execute @@ -14,6 +14,7 @@ error fatal-signal filename findprog-in +free-posix msvc-nothrow gettext-h spawn diff --git a/modules/execvpe b/modules/execvpe index c885cb8931..e29045dc66 100644 --- a/modules/execvpe +++ b/modules/execvpe @@ -8,6 +8,7 @@ m4/execvpe.m4 Depends-on: unistd extensions +free-posix [test $HAVE_EXECVPE = 0 || test $REPLACE_EXECVPE = 1] stdbool [test $HAVE_EXECVPE = 0 || test $REPLACE_EXECVPE = 1] findprog-in [test $HAVE_EXECVPE = 0 || test $REPLACE_EXECVPE = 1] execve [test $HAVE_EXECVPE = 0 || test $REPLACE_EXECVPE = 1] diff --git a/modules/fchdir b/modules/fchdir index eb53d25a4d..e58c73523a 100644 --- a/modules/fchdir +++ b/modules/fchdir @@ -17,6 +17,7 @@ fcntl [test $HAVE_FCHDIR = 0] fcntl-h [test $HAVE_FCHDIR = 0] filename [test $HAVE_FCHDIR = 0] filenamecat-lgpl [test $HAVE_FCHDIR = 0] +free-posix [test $HAVE_FCHDIR = 0] fstat [test $HAVE_FCHDIR = 0] getcwd-lgpl [test $HAVE_FCHDIR = 0] malloc-posix [test $HAVE_FCHDIR = 0] diff --git a/modules/file-has-acl b/modules/file-has-acl index 0f8ab37fdb..c41cde1d4b 100644 --- a/modules/file-has-acl +++ b/modules/file-has-acl @@ -8,6 +8,7 @@ m4/acl.m4 Depends-on: acl-permissions +free-posix stat configure.ac: diff --git a/modules/fprintf-posix b/modules/fprintf-posix index 87d64e7a0b..123fbea2d4 100644 --- a/modules/fprintf-posix +++ b/modules/fprintf-posix @@ -23,6 +23,7 @@ fseterr [test $REPLACE_FPRINTF = 1] vasnprintf [test $REPLACE_FPRINTF = 1] isnand-nolibm [test $REPLACE_FPRINTF = 1] isnanl-nolibm [test $REPLACE_FPRINTF = 1] +freee-posix [test $REPLACE_FPRINTF = 1] frexp-nolibm [test $REPLACE_FPRINTF = 1] frexpl-nolibm [test $REPLACE_FPRINTF = 1] printf-frexp [test $REPLACE_FPRINTF = 1] diff --git a/modules/getcwd-lgpl b/modules/getcwd-lgpl index 718351c381..ff1385725c 100644 --- a/modules/getcwd-lgpl +++ b/modules/getcwd-lgpl @@ -7,6 +7,7 @@ m4/getcwd.m4 Depends-on: unistd +free-posix [test $REPLACE_GETCWD = 1] strdup [test $REPLACE_GETCWD = 1] configure.ac: diff --git a/modules/getgroups b/modules/getgroups index 9926a12444..7625a535ad 100644 --- a/modules/getgroups +++ b/modules/getgroups @@ -7,6 +7,7 @@ m4/getgroups.m4 Depends-on: unistd +free-posix [test $HAVE_GETGROUPS = 0 || test $REPLACE_GETGROUPS = 1] malloc-posix [test $HAVE_GETGROUPS = 0 || test $REPLACE_GETGROUPS = 1] stdint [test $HAVE_GETGROUPS = 0 || test $REPLACE_GETGROUPS = 1] diff --git a/modules/link b/modules/link index 5ea0ac2ff9..93ccb192b0 100644 --- a/modules/link +++ b/modules/link @@ -7,6 +7,7 @@ m4/link.m4 Depends-on: unistd +free-posix [test $HAVE_LINK = 0 || test $REPLACE_LINK = 1] stat [test $HAVE_LINK = 0 || test $REPLACE_LINK = 1] strdup-posix [test $HAVE_LINK = 0 || test $REPLACE_LINK = 1] sys_stat [test $HAVE_LINK = 0 || test $REPLACE_LINK = 1] diff --git a/modules/linkat b/modules/linkat index 1fb4f8ff46..2541bf90e9 100644 --- a/modules/linkat +++ b/modules/linkat @@ -17,6 +17,7 @@ errno [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] fcntl-h [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] filenamecat-lgpl [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] filename [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] +free-posix [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] fstat [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] getcwd-lgpl [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] link-follow [test $HAVE_LINKAT = 0 || test $REPLACE_LINKAT = 1] diff --git a/modules/localename b/modules/localename index b0e84e37e3..fc097829be 100644 --- a/modules/localename +++ b/modules/localename @@ -16,6 +16,7 @@ extensions stdbool locale flexmember +free-posix strdup lock langinfo diff --git a/modules/mgetgroups b/modules/mgetgroups index f401cdfa80..bc8a9ddf25 100644 --- a/modules/mgetgroups +++ b/modules/mgetgroups @@ -7,6 +7,7 @@ lib/mgetgroups.h m4/mgetgroups.m4 Depends-on: +free-posix getgroups getugroups realloc-posix diff --git a/modules/mountlist b/modules/mountlist index 8ec4793355..043c7a2908 100644 --- a/modules/mountlist +++ b/modules/mountlist @@ -9,6 +9,7 @@ m4/mountlist.m4 Depends-on: fopen-gnu +free-posix getline open unlocked-io-internal diff --git a/modules/pipe-filter-gi b/modules/pipe-filter-gi index 152f9099d1..42c85ffdeb 100644 --- a/modules/pipe-filter-gi +++ b/modules/pipe-filter-gi @@ -13,6 +13,7 @@ wait-process error extern-inline fcntl-h +free-posix gettext-h stdbool stdint diff --git a/modules/posix_spawn-internal b/modules/posix_spawn-internal index 2aeb019578..f0f5cd107d 100644 --- a/modules/posix_spawn-internal +++ b/modules/posix_spawn-internal @@ -18,6 +18,7 @@ unistd filename [test $HAVE_POSIX_SPAWN = 0] concat-filename [test $HAVE_POSIX_SPAWN = 0] findprog-in [test $HAVE_POSIX_SPAWN = 0] +free-posix [test $HAVE_POSIX_SPAWN = 0] malloca [test $HAVE_POSIX_SPAWN = 0] windows-spawn [test $HAVE_POSIX_SPAWN = 0] diff --git a/modules/putenv b/modules/putenv index e39f1450f6..b14330ad87 100644 --- a/modules/putenv +++ b/modules/putenv @@ -8,6 +8,7 @@ m4/putenv.m4 Depends-on: stdlib environ [test $REPLACE_PUTENV = 1] +free-posix [test $REPLACE_PUTENV = 1] malloc-posix [test $REPLACE_PUTENV = 1] configure.ac: diff --git a/modules/read-file b/modules/read-file index 5d2be5bbf4..e087c3567e 100644 --- a/modules/read-file +++ b/modules/read-file @@ -9,6 +9,7 @@ m4/read-file.m4 Depends-on: explicit_bzero fopen-gnu +free-posix fstat ftello malloc-posix diff --git a/modules/rename b/modules/rename index 27d6d4a02f..07299c235a 100644 --- a/modules/rename +++ b/modules/rename @@ -10,6 +10,7 @@ stdio canonicalize-lgpl [test $REPLACE_RENAME = 1] chdir [test $REPLACE_RENAME = 1] dirname-lgpl [test $REPLACE_RENAME = 1] +free-posix [test $REPLACE_RENAME = 1] lstat [test $REPLACE_RENAME = 1] rmdir [test $REPLACE_RENAME = 1] same-inode [test $REPLACE_RENAME = 1] diff --git a/modules/savedir b/modules/savedir index 4210981565..e01aee877f 100644 --- a/modules/savedir +++ b/modules/savedir @@ -10,6 +10,7 @@ Depends-on: closedir dirent-safer fdopendir +free-posix opendir readdir stpcpy diff --git a/modules/spawn-pipe b/modules/spawn-pipe index f0e8dafc17..fb5b658859 100644 --- a/modules/spawn-pipe +++ b/modules/spawn-pipe @@ -16,6 +16,7 @@ error fatal-signal filename findprog-in +free-posix gettext-h msvc-nothrow open diff --git a/modules/striconv b/modules/striconv index 83f3f607d5..d4677a33cc 100644 --- a/modules/striconv +++ b/modules/striconv @@ -8,6 +8,7 @@ lib/striconv.c Depends-on: iconv iconv_open +free-posix strdup c-strcase diff --git a/modules/striconveh b/modules/striconveh index 78a6396f81..558e7c6f93 100644 --- a/modules/striconveh +++ b/modules/striconveh @@ -15,6 +15,7 @@ unistr/u8-mbtouc-unsafe unistr/u8-mbtouc unistr/u8-mbtoucr unistr/u8-uctomb +free-posix strdup c-strcase c-strcaseeq diff --git a/modules/supersede b/modules/supersede index d15430229e..4dbe887648 100644 --- a/modules/supersede +++ b/modules/supersede @@ -15,6 +15,7 @@ tempname canonicalize open unlink +free-posix ignore-value stat stat-time diff --git a/modules/vasnprintf b/modules/vasnprintf index 96cd300282..bcde2b9cfd 100644 --- a/modules/vasnprintf +++ b/modules/vasnprintf @@ -25,6 +25,7 @@ stdio alloca-opt attribute float +free-posix stdint xsize errno diff --git a/modules/vdprintf b/modules/vdprintf index 1100f0497b..87192a3fdc 100644 --- a/modules/vdprintf +++ b/modules/vdprintf @@ -8,6 +8,7 @@ m4/vdprintf.m4 Depends-on: stdio vasnprintf [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1] +free-posix [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1] full-write [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1] errno [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1] diff --git a/modules/vfprintf-posix b/modules/vfprintf-posix index c23fdef317..47794dd9b1 100644 --- a/modules/vfprintf-posix +++ b/modules/vfprintf-posix @@ -18,6 +18,7 @@ stdio nocrash printf-safe multiarch +free-posix [test $REPLACE_VFPRINTF = 1] fseterr [test $REPLACE_VFPRINTF = 1] vasnprintf [test $REPLACE_VFPRINTF = 1] isnand-nolibm [test $REPLACE_VFPRINTF = 1] diff --git a/modules/wcscoll b/modules/wcscoll index 1c2edb69b1..c15d7d5cf8 100644 --- a/modules/wcscoll +++ b/modules/wcscoll @@ -13,6 +13,7 @@ lib/wcscoll-impl.h m4/wcscoll.m4 Depends-on: +free-posix wchar configure.ac: diff --git a/modules/wcsxfrm b/modules/wcsxfrm index c57a821af8..2ac45848e9 100644 --- a/modules/wcsxfrm +++ b/modules/wcsxfrm @@ -8,6 +8,7 @@ lib/wcsxfrm-impl.h m4/wcsxfrm.m4 Depends-on: +free-posix wchar configure.ac: diff --git a/modules/xgetdomainname b/modules/xgetdomainname index 307aa5dca8..d1c9f24594 100644 --- a/modules/xgetdomainname +++ b/modules/xgetdomainname @@ -6,6 +6,7 @@ lib/xgetdomainname.h lib/xgetdomainname.c Depends-on: +free-posix getdomainname xalloc diff --git a/modules/xgethostname b/modules/xgethostname index 07cf83d96e..846df1c004 100644 --- a/modules/xgethostname +++ b/modules/xgethostname @@ -6,6 +6,7 @@ lib/xgethostname.h lib/xgethostname.c Depends-on: +free-posix gethostname xalloc @@ -22,4 +23,3 @@ GPL Maintainer: Jim Meyering -