Squid internals The cbdata interface (src/cbdata.c) (ctd.) How it works Each allocation has a 'cbdata' header prepended Each call to CBDATA_INIT_TYPE(_FREECB) creates a MemPool of the given type of size (sizeof(type) + sizeof(struct _cbdata)) Each call to cbdataAlloc() creates a new entry in the MemPool and hands off the data offset to the caller Each call to cbdataLock()/Unlock()/Free() simply backtracks to the beginning of the _cbdata header and does a simple check to make sure this _is_ a cbdata entry In cbdataFree(), the data is marked invalid and if there are any pending locks, the data is not freed. In cbdataUnlock(), there data is freed only if it is marked invalid and has no locks. The data pointer is freed by the function/id passed in the CBDATA_INIT_TYPE_FREECB. There does not have to be a free function as the code "knows" which MemPool the memory came from