From 6b1971fe39cc91ae450d28238fe3f81758d0e6fd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Oct 2017 10:37:55 -0700 Subject: [PATCH] s3: VFS: Ensure sys_getwd() doesn't leak memory on error on really old systems. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13069 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit fb9ce0685e5d46e3d7abf5fac07b4f626339a413) --- source3/lib/system.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source3/lib/system.c b/source3/lib/system.c index 99462b631c7..01c934277ac 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -605,11 +605,16 @@ char *sys_getwd(void) } return wd; #else + char *wd = NULL; char *s = SMB_MALLOC_ARRAY(char, PATH_MAX); if (s == NULL) { return NULL; } - return getwd(s); + wd = getwd(s); + if (wd == NULL) { + SAFE_FREE(s); + } + return wd; #endif } -- 2.11.4.GIT