Squid internals The cbdata allocator (src/cbdata.c) What is it ? A problem with so many callbacks is to issue a callback for some data structure which has previously been freed. The callback data (cbdata) interface provides a unified allocator and registry to verify the validity of memory and to deallocate memory when noone is using it Example CBDATA_INIT_TYPE_FREECB(type, freefunc);/* Create a new cbdata pool for C type 'type' */ foo = cbdataAlloc(type); /* Allocate of type 'type' */ ... cbdataLock(foo); /* Lock it to keep it valid */ ... some_blocking_operation_completes() if (cbdataValid(foo)) /* If the pointer is actually valid */ callback_func(..., foo); /* .. call the callback, safe :) */ cbdataUnlock(foo); /* Unlock it, dropping the refcount */ ... cbdataFree(foo); /* Free the data - freefunc is now called */