s3: VFS: Ensure sys_getwd() doesn't leak memory on error on really old systems.
authorJeremy Allison <jra@samba.org>
Tue, 3 Oct 2017 17:37:55 +0000 (10:37 -0700)
committerRalph Boehme <slow@samba.org>
Wed, 4 Oct 2017 08:06:15 +0000 (10:06 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13069

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/system.c

index 70ddf6a4dea0e5be2b52567585c8cb7d5cca828d..5baa8f7d3ff0e841389d0e430508350e94902045 100644 (file)
@@ -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
 }