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>
30 if ( (new = (void *) ber_memalloc( size )) == NULL ) {
32 LDAP_LOG( OPERATION, ERR,
33 "ch_malloc: allocation of %lu bytes failed\n", (long)size, 0,0 );
35 Debug( LDAP_DEBUG_ANY, "ch_malloc of %lu bytes failed\n",
53 if ( block == NULL ) {
54 return( ch_malloc( size ) );
61 if ( (new = (void *) ber_memrealloc( block, size )) == NULL ) {
63 LDAP_LOG( OPERATION, ERR,
64 "ch_realloc: reallocation of %lu bytes failed\n", (long)size, 0,0 );
66 Debug( LDAP_DEBUG_ANY, "ch_realloc of %lu bytes failed\n",
84 if ( (new = (void *) ber_memcalloc( nelem, size )) == NULL ) {
86 LDAP_LOG( OPERATION, ERR,
87 "ch_calloc: allocation of %lu elements of %lu bytes faild\n",
88 (long)nelem, (long)size, 0 );
90 Debug( LDAP_DEBUG_ANY, "ch_calloc of %lu elems of %lu bytes failed\n",
91 (long) nelem, (long) size, 0 );
107 if ( (new = ber_strdup( string )) == NULL ) {
109 LDAP_LOG( OPERATION, ERR,
110 "chr_strdup: duplication of \"%s\" failed\n", string, 0, 0 );
112 Debug( LDAP_DEBUG_ANY, "ch_strdup(%s) failed\n", string, 0, 0 );
115 exit( EXIT_FAILURE );