]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/ch_malloc.c
Fix modlist bug in last commit
[openldap] / servers / slurpd / ch_malloc.c
index cf3b79c0b93b10ad4859f8a9f087a8c3818524c2..9f119825fa8cd0774c119c79d320de6e826b65c8 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <stdio.h>
 
+#include <ac/stdlib.h>
 #include <ac/socket.h>
 
 #include "../slapd/slap.h"
  */
 void *
 ch_malloc(
-    unsigned long      size
+    ber_len_t  size
 )
 {
        void    *new;
 
-       if ( (new = (void *) malloc( size )) == NULL ) {
-               fprintf( stderr, "malloc of %lu bytes failed\n", size );
+       if ( (new = (void *) ber_memalloc( size )) == NULL ) {
+               fprintf( stderr, "malloc of %lu bytes failed\n",
+                       (long) size );
                exit( 1 );
        }
 
@@ -53,7 +55,7 @@ ch_malloc(
 void *
 ch_realloc(
     void               *block,
-    unsigned long      size
+    ber_len_t  size
 )
 {
        void    *new;
@@ -62,8 +64,13 @@ ch_realloc(
                return( ch_malloc( size ) );
        }
 
-       if ( (new = (void *) realloc( block, size )) == NULL ) {
-               fprintf( stderr, "realloc of %lu bytes failed\n", size );
+       if ( size == 0 ) {
+               ch_free( block );
+       }
+
+       if ( (new = (void *) ber_memrealloc( block, size )) == NULL ) {
+               fprintf( stderr, "realloc of %lu bytes failed\n",
+                       (long) size );
                exit( 1 );
        }
 
@@ -79,15 +86,15 @@ ch_realloc(
  */
 void *
 ch_calloc(
-    unsigned long      nelem,
-    unsigned long      size
+    ber_len_t  nelem,
+    ber_len_t  size
 )
 {
        void    *new;
 
-       if ( (new = (void *) calloc( nelem, size )) == NULL ) {
+       if ( (new = (void *) ber_memcalloc( nelem, size )) == NULL ) {
                fprintf( stderr, "calloc of %lu elems of %lu bytes failed\n",
-                   nelem, size );
+                   (long) nelem, (long) size );
                exit( 1 );
        }
 
@@ -104,8 +111,8 @@ ch_free(
 )
 {
     if ( p != NULL ) {
-       free( p );
+               ber_memfree( p );
     }
     return;
 }
-       
+