From 61d094543cf4722f45cb1bbc59c6d5cf371fefb3 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 23 May 2009 18:56:51 +0700 Subject: [PATCH 2/2] source4/client/smbumount.c(canonicalize): fixed memory leaks. Fixed memory leak when path too long or path is NULL (in this case I just check path to NULL before alloc memory). Found by cppcheck: [source4/client/smbumount.c:83]: (all) Memory leak: canonical [source4/client/smbumount.c:87]: (error) Memory leak: canonical --- source4/client/smbumount.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/source4/client/smbumount.c b/source4/client/smbumount.c index 420b8ac..7100629 100644 --- a/source4/client/smbumount.c +++ b/source4/client/smbumount.c @@ -72,18 +72,20 @@ umount_ok(const char *mount_point) static char * canonicalize (char *path) { - char *canonical = malloc (PATH_MAX + 1); + char *canonical = NULL; + if (path == NULL) + return NULL; + + canonical = malloc (PATH_MAX + 1); if (!canonical) { fprintf(stderr, "Error! Not enough memory!\n"); return NULL; } - if (path == NULL) - return NULL; - if (strlen(path) > PATH_MAX) { fprintf(stderr, "Mount point string too long\n"); + free(canonical); return NULL; } -- 1.6.3.1