From 877ec618c5c26cb4b49b09897985b5d6b8841bc8 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Tue, 19 Jan 2010 17:17:26 +0100 Subject: [PATCH] Cleanup win32 compat code --- bacula/src/win32/compat/compat.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bacula/src/win32/compat/compat.cpp b/bacula/src/win32/compat/compat.cpp index 0b806ce9de..1fc161e001 100644 --- a/bacula/src/win32/compat/compat.cpp +++ b/bacula/src/win32/compat/compat.cpp @@ -1161,6 +1161,7 @@ opendir(const char *path) { /* enough space for VSS !*/ int max_len = strlen(path) + MAX_PATH; + char *tspec = NULL; _dir *rval = NULL; if (path == NULL) { errno = ENOENT; @@ -1169,10 +1170,15 @@ opendir(const char *path) Dmsg1(100, "Opendir path=%s\n", path); rval = (_dir *)malloc(sizeof(_dir)); + if (!rval) { + goto err; + } memset (rval, 0, sizeof (_dir)); - if (rval == NULL) return NULL; - char *tspec = (char *)malloc(max_len); - if (tspec == NULL) return NULL; + + tspec = (char *)malloc(max_len); + if (!tspec) { + goto err; + } conv_unix_to_win32_path(path, tspec, max_len); Dmsg1(100, "win32 path=%s\n", tspec); @@ -1222,8 +1228,12 @@ opendir(const char *path) return (DIR *)rval; err: - free((void *)rval->spec); - free(rval); + if (rval) { + free(rval); + } + if (tspec) { + free(tspec); + } errno = b_errno_win32; return NULL; } -- 2.39.5