1 /* ch_malloc.c - malloc routines that test returns from malloc and friends */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
14 #include <ac/stdlib.h>
16 #include <ac/string.h>
17 #include <ac/socket.h>
21 BerMemoryFunctions ch_mfuncs = {
22 (BER_MEMALLOC_FN *)ch_malloc,
23 (BER_MEMCALLOC_FN *)ch_calloc,
24 (BER_MEMREALLOC_FN *)ch_realloc,
25 (BER_MEMFREE_FN *)ch_free
35 if ( (new = (void *) ber_memalloc_x( size, NULL )) == NULL ) {
37 LDAP_LOG( OPERATION, ERR,
38 "ch_malloc: allocation of %lu bytes failed\n", (long)size, 0,0 );
40 Debug( LDAP_DEBUG_ANY, "ch_malloc of %lu bytes failed\n",
58 if ( block == NULL ) {
59 return( ch_malloc( size ) );
66 ctx = sl_context( block );
68 return sl_realloc( block, size, ctx );
71 if ( (new = (void *) ber_memrealloc_x( block, size, NULL )) == NULL ) {
73 LDAP_LOG( OPERATION, ERR,
74 "ch_realloc: reallocation of %lu bytes failed\n", (long)size, 0,0 );
76 Debug( LDAP_DEBUG_ANY, "ch_realloc of %lu bytes failed\n",
94 if ( (new = (void *) ber_memcalloc_x( nelem, size, NULL )) == NULL ) {
96 LDAP_LOG( OPERATION, ERR,
97 "ch_calloc: allocation of %lu elements of %lu bytes faild\n",
98 (long)nelem, (long)size, 0 );
100 Debug( LDAP_DEBUG_ANY, "ch_calloc of %lu elems of %lu bytes failed\n",
101 (long) nelem, (long) size, 0 );
104 exit( EXIT_FAILURE );
117 if ( (new = ber_strdup_x( string, NULL )) == NULL ) {
119 LDAP_LOG( OPERATION, ERR,
120 "chr_strdup: duplication of \"%s\" failed\n", string, 0, 0 );
122 Debug( LDAP_DEBUG_ANY, "ch_strdup(%s) failed\n", string, 0, 0 );
125 exit( EXIT_FAILURE );
136 ctx = sl_context( ptr );
140 ber_memfree_x( ptr, NULL );