]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/smartall.c
Move putz test program to a test program directory under qt-console.
[bacula/bacula] / bacula / src / lib / smartall.c
index 7fe164f96c695a4675d08fac69f5287df6a0fca4..f991ceefdf94f4f2b2c1071892b2cb6908b0d3a2 100644 (file)
          Version $Id$
 
 */
-
 /*
-   Copyright (C) 2000-2006 Kern Sibbald
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as amended with additional clauses defined in the
-   file LICENSE in the main source directory.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
-   the file LICENSE for additional details.
-
- */
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2007 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
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   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
+   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 of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 
 #include "bacula.h"
 /* Use the real routines here */
@@ -132,6 +144,11 @@ static void *smalloc(const char *fname, int lineno, unsigned int nbytes)
       Emsg0(M_ABORT, 0, _("Out of memory\n"));
    }
    Dmsg4(1150, "smalloc %d at %x from %s:%d\n", nbytes, buf, fname, lineno);
+#if    SMALLOC_SANITY_CHECK > 0
+   if (sm_bytes > SMALLOC_SANITY_CHECK) {
+      Emsg0(M_ABORT, 0, _("Too much memory used."));
+   }
+#endif
    return (void *)buf;
 }
 
@@ -188,8 +205,10 @@ void sm_free(const char *file, int line, void *fp)
       V(mutex);
       Emsg2(M_ABORT, 0, _("Buffer overrun called from %s:%d\n"), file, line);
    }
-   sm_buffers--;
-   sm_bytes -= head->ablen;
+   if (sm_buffers > 0) {
+      sm_buffers--;
+      sm_bytes -= head->ablen;
+   }
 
    qdchain(qp);
    V(mutex);
@@ -283,8 +302,8 @@ void *sm_realloc(const char *fname, int lineno, void *ptr, unsigned int size)
       return NULL from  realloc()  and  leave  the  buffer  in  PTR
       intact.  */
 
-   sm_buffers--;
-   sm_bytes -= head->ablen;
+// sm_buffers--;
+// sm_bytes -= head->ablen;
 
    if ((buf = smalloc(fname, lineno, size)) != NULL) {
       memcpy(buf, ptr, (int) sm_min(size, osize));
@@ -369,16 +388,16 @@ void sm_dump(bool bufdump)
       if (ap->abfname != NULL) {
          unsigned memsize = ap->ablen - (HEAD_SIZE + 1);
          char errmsg[500];
+         char *cp = ((char *)ap) + HEAD_SIZE;
 
          bsnprintf(errmsg, sizeof(errmsg),
-           _("Orphaned buffer:  %6u bytes allocated at line %d of %s %s\n"),
-            memsize, ap->ablineno, my_name, ap->abfname
+           _("Orphaned buffer:  %s %6u bytes buf=%p allocated at %s:%d\n"),
+            my_name, memsize, cp, ap->abfname, ap->ablineno
          );
          fprintf(stderr, "%s", errmsg);
          if (bufdump) {
             char buf[20];
             unsigned llen = 0;
-            char *cp = ((char *) ap) + HEAD_SIZE;
 
             errmsg[0] = EOS;
             while (memsize) {