diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c index 73832e59ff1..02cad6c00dc 100644 --- a/lib/libc/gen/fts-compat.c +++ b/lib/libc/gen/fts-compat.c @@ -241,14 +241,15 @@ fts_close(sp) (void)close(sp->fts_rfd); } - /* Free up the stream pointer. */ - free(sp); - /* Set errno and return. */ if (!ISSET(FTS_NOCHDIR) && saved_errno) { + /* Free up the stream pointer. */ + free(sp); errno = saved_errno; return (-1); } + /* Free up the stream pointer. */ + free(sp); return (0); } diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 73832e59ff1..02cad6c00dc 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -241,14 +241,15 @@ fts_close(sp) (void)close(sp->fts_rfd); } - /* Free up the stream pointer. */ - free(sp); - /* Set errno and return. */ if (!ISSET(FTS_NOCHDIR) && saved_errno) { + /* Free up the stream pointer. */ + free(sp); errno = saved_errno; return (-1); } + /* Free up the stream pointer. */ + free(sp); return (0); }