]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/win32/filed/vss.h
authorAlain Spineux <alain@baculasystems.com>
Wed, 5 Aug 2020 08:08:29 +0000 (10:08 +0200)
committerEric Bollengier <eric@baculasystems.com>
Tue, 1 Mar 2022 14:36:17 +0000 (15:36 +0100)
This commit is the result of the squash of the following main commits:

Author: Alain Spineux <alain@baculasystems.com>
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())

bacula/src/win32/filed/vss.h

index 829bc403fe225066a5457a514fdb3e41c2a73193..90be3185061e24af6f1e8be6778ba121f13321f4 100644 (file)
@@ -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, ...) */