/* * Must be called with the mutex locked! */ static int DBmalloc_chain_check(const char *file,int line,int todo) { return( DBFmalloc_chain_check("malloc_chain_check",file,line,todo) ); }
SIZETYPE DBmalloc_size( CONST char * file, int line, CONST DATATYPE * cptr ) { char *func = "malloc_size"; register struct mlist *ptr; // initialize the malloc sub-system. MALLOC_INIT(); #ifdef MALLOC_PTHREAD if ( !malloc_preamble ) pthread_mutex_lock( &malloc_mutex ); #endif // IF malloc chain checking is on, go do it. if (malloc_opts & MOPT_CKCHAIN) { VOIDCAST DBFmalloc_chain_check(func, file, line, 1); } // // verify that cptr is within the malloc region and that it is on // the correct alignment // if ( (cptr < malloc_data_start) || (cptr > malloc_data_end) || ((((long) cptr) & malloc_round) != 0)) { malloc_errno = M_CODE_BAD_PTR; malloc_warning(func, file, line, (struct mlist *) NULL); #ifdef MALLOC_PTHREAD if ( !malloc_preamble ) pthread_mutex_unlock( &malloc_mutex ); #endif return( (SIZETYPE) -1 ); } // // convert pointer to mlist struct pointer. To do this we must // move the pointer backwards the correct number of bytes... // ptr = DATATOMLIST(cptr); // check the magic number if ((ptr->flag & M_MAGIC_BITS) != M_MAGIC) { malloc_errno = M_CODE_BAD_MAGIC; malloc_warning(func, file, line, (struct mlist *) NULL); #ifdef MALLOC_PTHREAD if ( !malloc_preamble ) pthread_mutex_unlock( &malloc_mutex ); #endif return( (SIZETYPE) -1 ); } // if this segment is not flagged as being in use if (!(ptr->flag & M_INUSE)) { malloc_errno = M_CODE_NOT_INUSE; malloc_warning(func, file, line, ptr); #ifdef MALLOC_PTHREAD if ( !malloc_preamble ) pthread_mutex_unlock( &malloc_mutex ); #endif return( (SIZETYPE) -1 ); } // check to see that the pointers are still connected if ((ptr->prev && (ptr->prev->next != ptr)) || (ptr->next && (ptr->next->prev != ptr)) || ((ptr->next == NULL) && (ptr->prev == NULL))) { malloc_errno = M_CODE_BAD_CONNECT; malloc_warning(func, file, line, ptr); #ifdef MALLOC_PTHREAD if ( !malloc_preamble ) pthread_mutex_unlock( &malloc_mutex ); #endif return( (SIZETYPE) -1 ); } // check fill regions for overflow VOIDCAST FILLCHECK(func, file, line, ptr, SHOWERRORS); #ifdef MALLOC_PTHREAD if ( !malloc_preamble ) pthread_mutex_unlock( &malloc_mutex ); #endif return( ptr->r_size ); } // end of DBmalloc_size(...)