From: Amos Jeffries Date: Thu, 5 Feb 2015 11:34:16 +0000 (-0800) Subject: Cleanup: de-duplicate cbdata deallocate actions X-Git-Tag: merge-candidate-3-v1~285 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=50e2f4c43cb2e05d91edadb9b26d5f75c5e1cc31;p=thirdparty%2Fsquid.git Cleanup: de-duplicate cbdata deallocate actions --- diff --git a/src/cbdata.cc b/src/cbdata.cc index 8c149ec790..829fb98936 100644 --- a/src/cbdata.cc +++ b/src/cbdata.cc @@ -276,38 +276,14 @@ cbdataInternalAlloc(cbdata_type type, const char *file, int line) return p; } -void * -cbdataInternalFree(void *p, const char *file, int line) +void +cbdataRealFree(cbdata *c, const char *file, const int line) { - cbdata *c; -#if HASHED_CBDATA - c = (cbdata *) hash_lookup(cbdata_htable, p); -#else - c = (cbdata *) (((char *) p) - cbdata::Offset); -#endif -#if USE_CBDATA_DEBUG - debugs(45, 3, p << " " << file << ":" << line); -#else - debugs(45, 9, p); -#endif - - c->check(__LINE__); - assert(c->valid); - c->valid = 0; -#if USE_CBDATA_DEBUG - - c->addHistory("Free", file, line); -#endif - - if (c->locks) { - debugs(45, 9, p << " has " << c->locks << " locks, not freeing"); - return NULL; - } + void *p = c; --cbdataCount; debugs(45, 9, "Freeing " << p); #if USE_CBDATA_DEBUG - dlinkDelete(&c->link, &cbdataEntries); #endif @@ -325,17 +301,47 @@ cbdataInternalFree(void *p, const char *file, int line) #if HASHED_CBDATA hash_remove_link(cbdata_htable, &c->hash); #if USE_CBDATA_DEBUG - debugs(45, 3, "Call delete " << (void*)c << " " << file << ":" << line); + debugs(45, 3, "Call delete " << p << " " << file << ":" << line); #endif delete c; - cbdata_index[theType].pool->freeOne((void *)p); #else #if USE_CBDATA_DEBUG - debugs(45, 3, "Call cbdata::~cbdata() " << (void*)c << " " << file << ":" << line); + debugs(45, 3, "Call cbdata::~cbdata() " << p << " " << file << ":" << line); #endif c->cbdata::~cbdata(); - cbdata_index[theType].pool->freeOne(c); #endif + cbdata_index[theType].pool->freeOne(p); +} + +void * +cbdataInternalFree(void *p, const char *file, int line) +{ + cbdata *c; +#if HASHED_CBDATA + c = (cbdata *) hash_lookup(cbdata_htable, p); +#else + c = (cbdata *) (((char *) p) - cbdata::Offset); +#endif +#if USE_CBDATA_DEBUG + debugs(45, 3, p << " " << file << ":" << line); +#else + debugs(45, 9, p); +#endif + + c->check(__LINE__); + assert(c->valid); + c->valid = 0; +#if USE_CBDATA_DEBUG + + c->addHistory("Free", file, line); +#endif + + if (c->locks) { + debugs(45, 9, p << " has " << c->locks << " locks, not freeing"); + return NULL; + } + + cbdataRealFree(c, file, line); return NULL; } @@ -414,41 +420,7 @@ cbdataInternalUnlock(const void *p) return; } - --cbdataCount; - - debugs(45, 9, "Freeing " << p); - -#if USE_CBDATA_DEBUG - - dlinkDelete(&c->link, &cbdataEntries); - -#endif - - /* This is ugly. But: operator delete doesn't get - * the type parameter, so we can't use that - * to free the memory. - * So, we free it ourselves. - * Note that this means a non-placement - * new would be a seriously bad idea. - * Lastly, if we where a templated class, - * we could use the normal delete operator - * and it would Just Work. RBC 20030902 - */ - cbdata_type theType = c->type; -#if HASHED_CBDATA - hash_remove_link(cbdata_htable, &c->hash); -#if USE_CBDATA_DEBUG - debugs(45, 3, "Call delete " << (void*)c << " " << file << ":" << line); -#endif - delete c; - cbdata_index[theType].pool->freeOne((void *)p); -#else -#if USE_CBDATA_DEBUG - debugs(45, 3, "Call cbdata::~cbdata() " << (void*)c << " " << file << ":" << line); -#endif - c->cbdata::~cbdata(); - cbdata_index[theType].pool->freeOne(c); -#endif + cbdataRealFree(c, file, line); } int