]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/smartall.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / lib / smartall.c
index 32f5fac221423e3dad278754fe04edccb570118a..5ad10e539a9f5ae88c24adf1fdeb29b26bb9c3b3 100644 (file)
@@ -19,7 +19,7 @@
 */
 
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   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
@@ -118,7 +118,7 @@ static void *smalloc(const char *fname, int lineno, unsigned int nbytes)
       head->abfname = bufimode ? NULL : fname;
       head->ablineno = (sm_ushort) lineno;
       /* Emplace end-clobber detector at end of buffer */
-      buf[nbytes - 1] = (((long) buf) & 0xFF) ^ 0xC5;
+      buf[nbytes - 1] = (uint8_t)((((long) buf) & 0xFF) ^ 0xC5);
       buf += HEAD_SIZE;  /* Increment to user data start */
       if (++sm_buffers > sm_max_buffers) {
          sm_max_buffers = sm_buffers;
@@ -188,8 +188,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 +285,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 -= osize;
+// sm_buffers--;
+// sm_bytes -= head->ablen;
 
    if ((buf = smalloc(fname, lineno, size)) != NULL) {
       memcpy(buf, ptr, (int) sm_min(size, osize));