[PATCH] Remove redundant code
Collin Funk
collin.funk1@gmail.com
Fri Oct 10 17:22:21 GMT 2025
Alejandro Colomar <alx@kernel.org> writes:
> diff --git a/io/ftw.c b/io/ftw.c
> index dce2e67f72..d6c53939d0 100644
> --- a/io/ftw.c
> +++ b/io/ftw.c
> @@ -306,9 +306,7 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
> if (newp == NULL)
> {
> /* No more memory. */
> - int save_err = errno;
> free (buf);
> - __set_errno (save_err);
> return -1;
> }
> buf = newp;
> @@ -327,9 +325,7 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
> data->dirstreams[data->actdir]->content = content;
> if (content == NULL)
> {
> - int save_err = errno;
> free (buf);
> - __set_errno (save_err);
> result = -1;
> }
> else
> @@ -571,7 +567,6 @@ fail:
> }
> else
> {
> - int save_err;
> char *runp = dir.content;
>
> while (result == 0 && *runp != '\0')
> @@ -584,9 +579,7 @@ fail:
> runp = endp + 1;
> }
>
> - save_err = errno;
> free (dir.content);
> - __set_errno (save_err);
> }
>
> if ((data->flags & FTW_ACTIONRETVAL) && result == FTW_SKIP_SIBLINGS)
I assume ftw was used outside of glibc at some point which would explain
the need to save the errno.
Gnulib uses fts so changing ftw is not a problem (unless someone
knows more and corrects my previous point).
Code using Gnulib can save errno before calling free, or it can depend
on the free-posix module which replaces the function if it clobbers
errno [1]:
Gnulib module: free-posix
Portability problems fixed by Gnulib:
This function may clobber errno on many platforms: glibc 2.32,
Mac OS X, FreeBSD, NetBSD, OpenBSD 4.4, Minix, AIX, HP-UX,
Cygwin, mingw, MSVC.
Collin
[1] https://www.gnu.org/software/gnulib/manual/html_node/free.html
More information about the Libc-alpha
mailing list