From 8844cec8f31b58fcd22cb4021615165ced2ea5c4 Mon Sep 17 00:00:00 2001 From: Conrad Meyer Date: Sat, 4 Mar 2017 20:46:57 +0000 Subject: [PATCH] fts: Fix a potential memory leak in error case Dan Krejsa reports a potential memory leak in an fts_build error case, detected by Coverity. (It doesn't seem to show up in Coverity Scan, so I don't have a CID to point to.) I don't know whether it is actually possible to arrive in this case with a non-empty 'head' list. The cost is low, though. One additional branch in a terminal error case isn't the end of the world. PR: 217125 Submitted by: Dan Krejsa --- lib/libc/gen/fts.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 4add4bbfbd8..2d51b8b379c 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -850,6 +850,7 @@ mem1: saved_errno = errno; (cur->fts_level == FTS_ROOTLEVEL ? FCHDIR(sp, sp->fts_rfd) : fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { + fts_lfree(head); cur->fts_info = FTS_ERR; SET(FTS_STOP); return (NULL);