]> git.sur5r.net Git - openldap/blob - servers/slapd/ch_malloc.c
(re)introduce o_connid such that STATS doesn't need c_mutex (which it
[openldap] / servers / slapd / ch_malloc.c
1 /* ch_malloc.c - malloc routines that test returns from malloc and friends */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/stdlib.h>
8
9 #include <ac/string.h>
10 #include <ac/socket.h>
11
12 #include "slap.h"
13
14 void *
15 ch_malloc(
16     ber_len_t   size
17 )
18 {
19         void    *new;
20
21         if ( (new = (void *) ber_memalloc( size )) == NULL ) {
22                 Debug( LDAP_DEBUG_ANY, "ch_malloc of %lu bytes failed\n",
23                         (long) size, 0, 0 );
24                 exit( 1 );
25         }
26
27         return( new );
28 }
29
30 void *
31 ch_realloc(
32     void                *block,
33     ber_len_t   size
34 )
35 {
36         void    *new;
37
38         if ( block == NULL ) {
39                 return( ch_malloc( size ) );
40         }
41
42         if( size == 0 ) {
43                 ch_free( block );
44         }
45
46         if ( (new = (void *) ber_memrealloc( block, size )) == NULL ) {
47                 Debug( LDAP_DEBUG_ANY, "ch_realloc of %lu bytes failed\n",
48                         (long) size, 0, 0 );
49                 exit( 1 );
50         }
51
52         return( new );
53 }
54
55 void *
56 ch_calloc(
57     ber_len_t   nelem,
58     ber_len_t   size
59 )
60 {
61         void    *new;
62
63         if ( (new = (void *) ber_memcalloc( nelem, size )) == NULL ) {
64                 Debug( LDAP_DEBUG_ANY, "ch_calloc of %lu elems of %lu bytes failed\n",
65                   (long) nelem, (long) size, 0 );
66                 exit( 1 );
67         }
68
69         return( new );
70 }
71
72 char *
73 ch_strdup(
74     const char *string
75 )
76 {
77         char    *new;
78
79         if ( (new = ber_strdup( string )) == NULL ) {
80                 Debug( LDAP_DEBUG_ANY, "ch_strdup(%s) failed\n", string, 0, 0 );
81                 exit( 1 );
82         }
83
84         return( new );
85 }
86
87 void
88 ch_free( void *ptr )
89 {
90         ber_memfree( ptr );
91 }