From: Alain Spineux Date: Wed, 5 Aug 2020 08:08:29 +0000 (+0200) Subject: BEE Backport bacula/src/win32/filed/vss.h X-Git-Tag: Release-11.3.2~1324 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5089cb86e609bd95a4466ce22eb4ddd66a26f5f5;p=thirdparty%2Fbacula.git BEE Backport bacula/src/win32/filed/vss.h This commit is the result of the squash of the following main commits: Author: Alain Spineux Date: Tue Jun 12 18:42:49 2018 +0200 win32: plugin memory allocation cleanup - use bmalloc(len) instead of new char[len] (also for WCHAR) - always use bfree() (or safe_bfree()) for memory allocated with bmalloc() (instead of delete or safe_delete()) --- diff --git a/bacula/src/win32/filed/vss.h b/bacula/src/win32/filed/vss.h index 829bc403fe..90be318506 100644 --- a/bacula/src/win32/filed/vss.h +++ b/bacula/src/win32/filed/vss.h @@ -44,6 +44,7 @@ struct IVssAsync; #define bwcsdup(str) wcscpy((WCHAR *)bmalloc((wcslen(str)+1)*sizeof(WCHAR)),(str)) +#define safe_bfree(buf) if (buf) { bfree(buf); buf = NULL; } /* The MTabEntry class is representing a mounted volume, * it associates a volume name with mount paths and a device name @@ -74,7 +75,7 @@ public: if (VolumeName[last - 1] == L'\\') { volumeName = bwcsdup(VolumeName); } else { /* \\ + \0 */ - volumeName = (WCHAR *)bmalloc(last+2*sizeof(WCHAR)); + volumeName = (WCHAR *)bmalloc((last+1)*sizeof(WCHAR)); wcscpy(volumeName, VolumeName); volumeName[last] = L'\\'; volumeName[last+1] = L'\0'; @@ -93,22 +94,10 @@ public: }; void destroy() { - if (mountPaths) { - free(mountPaths); - mountPaths = NULL; - } - if (volumeName) { - free(volumeName); - volumeName = NULL; - } - if (deviceName) { - free(deviceName); - deviceName = NULL; - } - if (shadowCopyName) { - free(shadowCopyName); - shadowCopyName = NULL; - } + safe_bfree(mountPaths); + safe_bfree(volumeName); + safe_bfree(deviceName); + safe_bfree(shadowCopyName); }; /* Return the drive type (cdrom, fixed, network, ...) */