/** * This is for internal use * * @see tfree */ static void __tfree ( void** mem ) { if ( !mem ) return; __tfree( mem[0] ); __tfree( mem[1] ); free( mem ); }
/** * Deallocate all the descendants of parent(mem) recursively. * * @param mem pointer to previously talloc'ed memory chunk. */ static void __tfree(void *mem) { if (!mem) return; /* Fail if the tree hierarchy has cycles. */ assert(prev(mem)); prev(mem) = NULL; __tfree(child(mem)); __tfree(next(mem)); free(usr2raw(mem)); }
/** * Deallocate a talloc'ed memory chunk and all the chunks depending on it. * * @param mem pointer to previously talloc'ed memory chunk. * * @return always NULL, can be safely ignored. */ void *tfree(void *mem) { if (!mem) return NULL; talloc_set_parent(mem, NULL); __tfree(child(mem)); free(usr2raw(mem)); return NULL; }
/** * Free memory * * @param mem pointer to previously talloc'ed memory */ void tfree ( void* mem ) { if ( !mem ) return; if (mutex == NULL) { init_mutex(); } pthread_mutex_lock(mutex); talloc_set_parent( mem, NULL ); __tfree( ((void**)mem)[-3] ); free( (void**)mem - 3 ); pthread_mutex_unlock(mutex); }