From dd559118ab3f065ae230b324c3fe4bb1c9b7ca56 Mon Sep 17 00:00:00 2001 From: Andrew Walker Date: Tue, 20 Apr 2021 15:34:44 -0400 Subject: [PATCH] Fix leak in libc NFSv4 flags parsing Free memory allocated by strdup() in parse_flags_verbose(). Submitted by: Andrew Walker Reported by: valgrind Reviewed by: allanjude, freqlabs, rpokala MFC after: 3 days Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D29871 --- lib/libc/posix1e/acl_support_nfs4.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/libc/posix1e/acl_support_nfs4.c b/lib/libc/posix1e/acl_support_nfs4.c index 3962eaa6daa8..92ec666b2313 100644 --- a/lib/libc/posix1e/acl_support_nfs4.c +++ b/lib/libc/posix1e/acl_support_nfs4.c @@ -142,9 +142,10 @@ parse_flags_verbose(const char *strp, uint32_t *var, int *try_compact) { int i, found, ever_found = 0; - char *str, *flag; + char *str, *flag, *to_free; str = strdup(strp); + to_free = str; *try_compact = 0; *var = 0; @@ -166,12 +167,12 @@ parse_flags_verbose(const char *strp, uint32_t *var, "invalid flag \"%s\"", flags_name, flag); else *try_compact = 1; - free(str); + free(to_free); return (-1); } } - free(str); + free(to_free); return (0); }