]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/smartall.h
Fix #define when using --disable-smartalloc
[bacula/bacula] / bacula / src / lib / smartall.h
index 6661e089a4e61a52da9133e90ae87415edc4328d..4973f4fa255819c4a6fd5ca6ed3896bc6b08d975 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark ofJohn Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 
         Definitions for the smart memory allocator
 
-     Version $Id$
-
 */
 
+#ifndef SMARTALLOC_H
+#define SMARTALLOC_H
+
 extern uint64_t DLL_IMP_EXP sm_max_bytes;
 extern uint64_t DLL_IMP_EXP sm_bytes;
 extern uint32_t DLL_IMP_EXP sm_max_buffers;
@@ -87,8 +88,8 @@ extern int sm_check_rtn(const char *fname, int lineno, bool bufdump);
 #define sm_dump(x)
 #define sm_static(x)
 #define sm_new_owner(a, b, c)
-#define sm_malloc(f, l, n) malloc(n)
-
+#define sm_malloc(f, l, n)     malloc(n)
+#define sm_free(f, l, n)       free(n)
 #define sm_check(f, l, fl)
 #define sm_check_rtn(f, l, fl) 1
 
@@ -99,52 +100,56 @@ extern void *b_malloc();
 #endif
 
 #ifdef SMARTALLOC
-// #ifdef xxx
 
 #define New(type) new(__FILE__, __LINE__) type
 
+/* We do memset(0) because it's not possible to memset a class when
+ * using subclass with virtual functions
+ */
+
 class SMARTALLOC
 {
 public:
 
 void *operator new(size_t s, const char *fname, int line)
 {
-  void *p = sm_malloc(fname, line, s > sizeof(int) ? (unsigned int)s : sizeof(int));
-  return p;
+   size_t size =  s > sizeof(int) ? (unsigned int)s : sizeof(int);
+   void *p = sm_malloc(fname, line, size);
+   memset(p, 0, size);
+   return p;
 }
 void *operator new[](size_t s, const char *fname, int line)
 {
-   void *p = sm_malloc(fname, line, s > sizeof(int) ? (unsigned int)s : sizeof(int));
+   size_t size =  s > sizeof(int) ? (unsigned int)s : sizeof(int);
+   void *p = sm_malloc(fname, line, size);
+   memset(p, 0, size);
    return p;
 }
+
 void  operator delete(void *ptr)
 {
    free(ptr);
 }
-void  operator delete[](void *ptr, size_t i)
+void  operator delete[](void *ptr, size_t /*i*/)
 {
-   (void)i;                           /* eliminate compiler complaints */
    free(ptr);
 }
 
-void  operator delete(void *ptr, const char *fname, int line)
+void  operator delete(void *ptr, const char * /*fname*/, int /*line*/)
 {
-   (void)fname; (void)line;          /* eliminate compiler complaints */
    free(ptr);
 }
-void  operator delete[](void *ptr, size_t i, const char *fname, int line)
+void  operator delete[](void *ptr, size_t /*i*/, 
+                        const char * /*fname*/, int /*line*/)
 {
-   (void)i; (void)fname; (void)line; /* eliminate compiler complaints */
    free(ptr);
 }
 
-
 private:
 void *operator new(size_t s) throw() { (void)s; return 0; }
 void *operator new[](size_t s) throw() { (void)s; return 0; }
 };
 
-
 #else
 
 #define New(type) new type
@@ -152,21 +157,23 @@ void *operator new[](size_t s) throw() { (void)s; return 0; }
 class SMARTALLOC
 {
    public:
-      void *operator new(size_t s)
-      {
-          return malloc(s);
+      void *operator new(size_t s) {
+         void *p = malloc(s);
+         memset(p, 0, s);
+         return p;
       }
-      void *operator new[](size_t s)
-      {
-          return malloc(s);
+      void *operator new[](size_t s) {
+         void *p = malloc(s);
+         memset(p, 0, s);
+         return p;
       }
-      void  operator delete(void *ptr)
-      {
+      void  operator delete(void *ptr) {
           free(ptr);
       }
-      void  operator delete[](void *ptr, size_t i)
-      {
+      void  operator delete[](void *ptr, size_t i) {
           free(ptr);
       }
 };
-#endif
+#endif  /* SMARTALLOC */
+   
+#endif  /* !SMARTALLOC_H */