This patch is generated from the cbdata-20010105 branch of HEAD in squid
Thu Sep 11 11:58:58 2003 GMT
See http://devel.squid-cache.org/

Index: squid/doc/Programming-Guide/prog-guide.sgml
diff -u squid/doc/Programming-Guide/prog-guide.sgml:1.4 squid/doc/Programming-Guide/prog-guide.sgml:1.3.16.3
--- squid/doc/Programming-Guide/prog-guide.sgml:1.4	Wed Jan  3 23:23:58 2001
+++ squid/doc/Programming-Guide/prog-guide.sgml	Thu Jan  4 05:03:57 2001
@@ -257,7 +257,7 @@
 	and <tt/squid.conf/.  <tt/cf_parser.c/ is included directly
 	into <tt/cache_cf.c/ at compile time.
 
-<sect1>Callback Data Database
+<sect1>Callback Data Allocator
 
 	<P>
 	Squid's extensive use of callback functions makes it very
@@ -1840,10 +1840,6 @@
 	It should also populate the _data member with a pointer to policy
 	specific data.
 
-<P>
-	Prior to returning the created instance must be registered as
-	callback-data by calling cbdataAdd().
-
 <sect3>Walker
 
 <P>
@@ -1852,10 +1848,6 @@
 	policy implementation must make sure to NULL fill the structure prior
 	to populating it in order to assure future API compability.
 
-<P>
-	Prior to returning the created instance must be registered as
-	callback-data by calling cbdataAdd().
-
 <sect2>Design notes/bugs
 
 <P>
@@ -2037,8 +2029,8 @@
 	<P>
 	To be written...
 
-<!-- %%%% Chapter : Callback Data Base %%%% -->
-<sect>Callback Data Database
+<!-- %%%% Chapter : Callback Data Allocator %%%% -->
+<sect>Callback Data Allocator
 
 	<P>
 	Squid's extensive use of callback functions makes it very
@@ -2060,14 +2052,14 @@
 	before the operation completes.
 
 	<P>
-	The callback data database lets us do this in a uniform and
-	safe manner.  Every callback_data pointer must be added to the
-	database.  It is then locked while the blocking operation executes
-	elsewhere, and is freed when the operation completes.  The normal
-	sequence of events is:
+	The callback data allocator lets us do this in a uniform and
+	safe manner.  The callback data allocator is used to allocate,
+	track and free memory pool objects used during callback
+	operations.  Allocated memory is locked while the blocking
+	operation executes elsewhere, and is freed when the operation
+	completes.  The normal sequence of events is:
 <verb>
-	callback_data = malloc(...);
-	cbdataAdd(callback_data);
+	callback_data = CBDATA_ALLOC(type_of_data, free_handler);
 	...
 	cbdataLock(callback_data);
 	fooOperationStart(bar, callback_func, callback_data);
@@ -2083,8 +2075,7 @@
 	With this scheme, nothing bad happens if <tt/cbdataFree/ gets called
 	before <tt/cbdataUnlock/:
 <verb>
-	callback_data = malloc(...);
-	cbdataAdd(callback_data);
+	callback_data = CBDATA_ALLOC(...);
 	...
 	cbdataLock(callback_data);
 	fooOperationStart(bar, callback_func, callback_data);
Index: squid/src/acl.c
diff -u squid/src/acl.c:1.7 squid/src/acl.c:1.5.4.2
--- squid/src/acl.c:1.7	Wed Jan  3 23:23:58 2001
+++ squid/src/acl.c	Thu Jan  4 04:06:40 2001
@@ -898,7 +898,7 @@
 	debug(28, 0) ("aclParseAccessLine: missing 'allow' or 'deny'.\n");
 	return;
     }
-    A = memAllocate(MEM_ACL_ACCESS);
+    A = CBDATA_ALLOC(acl_access, NULL);
 
     if (!strcmp(t, "allow"))
 	A->allow = 1;
@@ -908,7 +908,7 @@
 	debug(28, 0) ("%s line %d: %s\n",
 	    cfg_filename, config_lineno, config_input_line);
 	debug(28, 0) ("aclParseAccessLine: expecting 'allow' or 'deny', got '%s'.\n", t);
-	memFree(A, MEM_ACL_ACCESS);
+	cbdataFree(A);
 	return;
     }
 
@@ -940,7 +940,7 @@
 	debug(28, 0) ("%s line %d: %s\n",
 	    cfg_filename, config_lineno, config_input_line);
 	debug(28, 0) ("aclParseAccessLine: Access line contains no ACL's, skipping\n");
-	memFree(A, MEM_ACL_ACCESS);
+        cbdataFree(A);
 	return;
     }
     A->cfgline = xstrdup(config_input_line);
@@ -948,7 +948,6 @@
     for (B = *head, T = head; B; T = &B->next, B = B->next);
     *T = A;
     /* We lock _acl_access structures in aclCheck() */
-    cbdataAdd(A, memFree, MEM_ACL_ACCESS);
 }
 
 /**************/
@@ -1813,8 +1812,8 @@
     const char *ident)
 {
     int i;
-    aclCheck_t *checklist = memAllocate(MEM_ACLCHECK_T);
-    cbdataAdd(checklist, memFree, MEM_ACLCHECK_T);
+    aclCheck_t *checklist;
+    checklist = CBDATA_ALLOC(aclCheck_t, NULL);
     checklist->access_list = A;
     /*
      * aclCheck() makes sure checklist->access_list is a valid
Index: squid/src/asn.c
diff -u squid/src/asn.c:1.5 squid/src/asn.c:1.4.12.2
--- squid/src/asn.c:1.5	Mon Dec 18 04:17:57 2000
+++ squid/src/asn.c	Thu Jan  4 04:06:40 2001
@@ -151,6 +151,7 @@
 
 /* initialize the radix tree structure */
 
+CBDATA_TYPE(ASState);
 void
 asnInit(void)
 {
@@ -162,6 +163,7 @@
     rn_inithead((void **) &AS_tree_head, 8);
     asnAclInitialize(Config.aclList);
     cachemgrRegister("asndb", "AS Number Database", asnStats, 0, 1);
+    CBDATA_INIT_TYPE(ASState);
 }
 
 void
@@ -187,8 +189,8 @@
     LOCAL_ARRAY(char, asres, 4096);
     StoreEntry *e;
     request_t *req;
-    ASState *asState = xcalloc(1, sizeof(ASState));
-    cbdataAdd(asState, cbdataXfree, 0);
+    ASState *asState;
+    asState = CBDATA_ALLOC(ASState, NULL);
     debug(53, 3) ("asnCacheStart: AS %d\n", as);
     snprintf(asres, 4096, "whois://%s/!gAS%d", Config.as_whois_server, as);
     asState->as_number = as;
Index: squid/src/authenticate.c
diff -u squid/src/authenticate.c:1.4 squid/src/authenticate.c:1.4.14.1
--- squid/src/authenticate.c:1.4	Fri Nov  3 00:39:20 2000
+++ squid/src/authenticate.c	Sun Dec 17 00:20:04 2000
@@ -78,6 +78,8 @@
     helperStats(sentry, authenticators);
 }
 
+CBDATA_TYPE(authenticateStateData);
+
 /**** PUBLIC FUNCTIONS ****/
 
 
@@ -94,8 +96,7 @@
 	handler(data, NULL);
 	return;
     }
-    r = xcalloc(1, sizeof(authenticateStateData));
-    cbdataAdd(r, cbdataXfree, 0);
+    r = CBDATA_ALLOC(authenticateStateData, NULL);
     r->handler = handler;
     cbdataLock(data);
     r->data = data;
@@ -123,6 +124,7 @@
 	    authenticateStats, 0, 1);
 	init++;
     }
+    CBDATA_INIT_TYPE(authenticateStateData);
 }
 
 void
Index: squid/src/cache_cf.c
diff -u squid/src/cache_cf.c:1.9 squid/src/cache_cf.c:1.6.4.3
--- squid/src/cache_cf.c:1.9	Thu Jan  4 22:38:08 2001
+++ squid/src/cache_cf.c	Fri Jan  5 00:09:02 2001
@@ -393,8 +393,7 @@
     if (Config.Wais.relayHost) {
 	if (Config.Wais.peer)
 	    cbdataFree(Config.Wais.peer);
-	Config.Wais.peer = memAllocate(MEM_PEER);
-	cbdataAdd(Config.Wais.peer, peerDestroy, MEM_PEER);
+	Config.Wais.peer = CBDATA_ALLOC(peer, peerDestroy);
 	Config.Wais.peer->host = xstrdup(Config.Wais.relayHost);
 	Config.Wais.peer->http_port = Config.Wais.relayPort;
     }
@@ -1101,7 +1100,7 @@
     char *token = NULL;
     peer *p;
     int i;
-    p = memAllocate(MEM_PEER);
+    p = CBDATA_ALLOC(peer, peerDestroy);
     p->http_port = CACHE_HTTP_PORT;
     p->icp.port = CACHE_ICP_PORT;
     p->weight = 1;
@@ -1189,8 +1188,6 @@
 	p->carp.hash = ROTATE_LEFT(p->carp.hash, 21);
     }
 #endif
-    /* This must preceed peerDigestCreate */
-    cbdataAdd(p, peerDestroy, MEM_PEER);
 #if USE_CACHE_DIGESTS
     if (!p->options.no_digest) {
 	p->digest = peerDigestCreate(p);
Index: squid/src/cbdata.c
diff -u squid/src/cbdata.c:1.4 squid/src/cbdata.c:1.4.14.6
--- squid/src/cbdata.c:1.4	Fri Nov  3 00:39:20 2000
+++ squid/src/cbdata.c	Thu Jan  4 04:29:10 2001
@@ -3,7 +3,8 @@
  * $Id: squid-cbdata-20010105-HEAD,v 1.1 2004/08/17 20:55:12 hno Exp $
  *
  * DEBUG: section 45    Callback Data Registry
- * AUTHOR: Duane Wessels
+ * ORIGINAL AUTHOR: Duane Wessels
+ * Modified by Moez Mahfoudh (08/12/2000)
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
  * ----------------------------------------------------------
@@ -44,16 +45,15 @@
  * 
  * In terms of time, the sequence goes something like this:
  * 
- * foo = xcalloc(sizeof(foo));
- * cbdataAdd(foo);
+ * foo = cbdataAlloc(sizeof(foo),NULL);
  * ...
- * cbdataLock(foo);
  * some_blocking_operation(..., callback_func, foo);
- * ...
- * some_blocking_operation_completes()
- * if (cbdataValid(foo))
- * callback_func(..., foo)
- * cbdataUnlock(foo);
+ *   cbdataLock(foo);
+ *   ...
+ *   some_blocking_operation_completes()
+ *   if (cbdataValid(foo))
+ *   callback_func(..., foo)
+ *   cbdataUnlock(foo);
  * ...
  * cbdataFree(foo);
  * 
@@ -66,107 +66,131 @@
 
 #include "squid.h"
 
-static hash_table *htable = NULL;
-
 static int cbdataCount = 0;
 
 typedef struct _cbdata {
-    hash_link hash;		/* must be first */
     int valid;
     int locks;
     CBDUNL *unlock_func;
-    int id;
+    int type;	/* move to CBDATA_DEBUG with type argument to cbdataFree */
 #if CBDATA_DEBUG
     const char *file;
     int line;
 #endif
+    void *y;	/* cookie used while debugging */
+    union {
+	void *pointer;
+	double double_float;
+	int integer;
+    } data;
 } cbdata;
 
-static HASHCMP cbdata_cmp;
-static HASHHASH cbdata_hash;
-static void cbdataReallyFree(cbdata * c);
 static OBJH cbdataDump;
-static MemPool *cbdata_pool = NULL;
 
-static int
-cbdata_cmp(const void *p1, const void *p2)
+static MemPool **cbdata_memory_pool = NULL;
+int cbdata_types = 0;
+
+#define OFFSET_OF(type, member) ((int)(char *)&((type *)0L)->member)
+
+void
+cbdataInitType(cbdata_type type, char *name, int size)
 {
-    return (char *) p1 - (char *) p2;
+    char *label;
+    if (type >= cbdata_types) {
+	cbdata_memory_pool = xrealloc(cbdata_memory_pool, (type+1) * sizeof(*cbdata_memory_pool));
+	memset(&cbdata_memory_pool[cbdata_types], 0,
+		(type + 1 - cbdata_types) * sizeof(*cbdata_memory_pool));
+	cbdata_types = type + 1;
+    }
+    if (cbdata_memory_pool[type])
+	return;
+    label = xmalloc(strlen(name)+20);
+    snprintf(label, strlen(name)+20, "cbdata %s (%d)", name, (int)type);
+    assert(OFFSET_OF(cbdata, data) == (sizeof(cbdata)-sizeof(((cbdata *)NULL)->data)));
+    cbdata_memory_pool[type]=memPoolCreate(label, size+OFFSET_OF(cbdata,data));
 }
 
-static unsigned int
-cbdata_hash(const void *p, unsigned int mod)
+cbdata_type cbdataAddType(cbdata_type type, char *name, int size)
 {
-    return ((unsigned long) p >> 8) % mod;
+    if (type)
+	return type;
+    type = cbdata_types;
+    cbdataInitType(type, name, size);
+    return type;
 }
 
-
 void
 cbdataInit(void)
 {
     debug(45, 3) ("cbdataInit\n");
-    if (cbdata_pool == NULL) {
-	cbdata_pool = memPoolCreate("cbdata", sizeof(cbdata));
-    }
-    htable = hash_create(cbdata_cmp, 1 << 8, cbdata_hash);
     cachemgrRegister("cbdata",
 	"Callback Data Registry Contents",
 	cbdataDump, 0, 1);
+/* TEMPORARILY DEFINED IN squid.h
+#define CREATE_CBDATA(type) cbdataInitType(CBDATA_##type, #type, sizeof(type))
+*/
+    CREATE_CBDATA(acl_access);
+    CREATE_CBDATA(aclCheck_t);
+    CREATE_CBDATA(clientHttpRequest);
+    CREATE_CBDATA(ConnStateData);
+    CREATE_CBDATA(ErrorState);
+    CREATE_CBDATA(FwdState);
+    CREATE_CBDATA(generic_cbdata);
+    CREATE_CBDATA(helper);
+    CREATE_CBDATA(helper_server);
+    CREATE_CBDATA(HttpStateData);
+    CREATE_CBDATA(peer);
+    CREATE_CBDATA(ps_state);
+    CREATE_CBDATA(RemovalPolicy);
+    CREATE_CBDATA(RemovalPolicyWalker);
+    CREATE_CBDATA(RemovalPurgeWalker);
+    CREATE_CBDATA(store_client);
+    CREATE_CBDATA(storeIOState);
 }
 
-void
+void *
 #if CBDATA_DEBUG
-cbdataAddDbg(const void *p, CBDUNL * unlock_func, int id, const char *file, int line)
+cbdataInternalAllocDbg(cbdata_type type, CBDUNL * unlock_func, const char *file, int line)
 #else
-cbdataAdd(const void *p, CBDUNL * unlock_func, int id)
+cbdataInternalAlloc(cbdata_type type, CBDUNL * unlock_func)
 #endif
 {
-    cbdata *c;
-    assert(p);
-    debug(45, 3) ("cbdataAdd: %p\n", p);
-    assert(htable != NULL);
-    assert(hash_lookup(htable, p) == NULL);
-    c = memPoolAlloc(cbdata_pool);
-    c->hash.key = (void *) p;
-    c->valid = 1;
-    c->unlock_func = unlock_func;
-    c->id = id;
+    cbdata *p;
+    assert(type > 0 && type < cbdata_types);
+    p = memPoolAlloc(cbdata_memory_pool[type]);
+    p->type = type;
+    p->unlock_func=unlock_func;
+    p->valid=1;
+    p->locks=0;
 #if CBDATA_DEBUG
-    c->file = file;
-    c->line = line;
+    p->file = file;
+    p->line = line;
 #endif
-    hash_join(htable, &c->hash);
+    p->y = p;
     cbdataCount++;
-}
-
-static void
-cbdataReallyFree(cbdata * c)
-{
-    CBDUNL *unlock_func = c->unlock_func;
-    void *p = c->hash.key;
-    int id = c->id;
-    hash_remove_link(htable, (hash_link *) c);
-    cbdataCount--;
-    memPoolFree(cbdata_pool, c);
-    debug(45, 3) ("cbdataReallyFree: Freeing %p\n", p);
-    if (unlock_func)
-	unlock_func(p, id);
+    
+    return (void *)&p->data;
 }
 
 void
 cbdataFree(void *p)
 {
-    cbdata *c = (cbdata *) hash_lookup(htable, p);
-    assert(p);
+    cbdata *c;
     debug(45, 3) ("cbdataFree: %p\n", p);
-    assert(c != NULL);
+    assert(p);
+    c = (cbdata *) (((char *)p)-OFFSET_OF(cbdata,data));
+    assert(c->y==c);
     c->valid = 0;
     if (c->locks) {
 	debug(45, 3) ("cbdataFree: %p has %d locks, not freeing\n",
 	    p, c->locks);
 	return;
     }
-    cbdataReallyFree(c);
+    cbdataCount--;
+    debug(45, 3) ("cbdataFree: Freeing %p\n", p);
+    if (c->unlock_func)
+	c->unlock_func((void *)p);
+    memPoolFree(cbdata_memory_pool[c->type], c);
 }
 
 void
@@ -179,7 +203,8 @@
     cbdata *c;
     if (p == NULL)
 	return;
-    c = (cbdata *) hash_lookup(htable, p);
+    c = (cbdata *) (((char *)p)-OFFSET_OF(cbdata,data));
+    assert(c->y == c);
     debug(45, 3) ("cbdataLock: %p\n", p);
     assert(c != NULL);
     c->locks++;
@@ -199,7 +224,8 @@
     cbdata *c;
     if (p == NULL)
 	return;
-    c = (cbdata *) hash_lookup(htable, p);
+    c = (cbdata *) (((char *)p)-OFFSET_OF(cbdata,data));
+    assert(c->y == c);
     debug(45, 3) ("cbdataUnlock: %p\n", p);
     assert(c != NULL);
     assert(c->locks > 0);
@@ -210,50 +236,29 @@
 #endif
     if (c->valid || c->locks)
 	return;
-    cbdataReallyFree(c);
+    cbdataCount--;
+    debug(45, 3) ("cbdataUnlock: Freeing %p\n", p);
+    if (c->unlock_func)
+	c->unlock_func((void *)p);
+    memPoolFree(cbdata_memory_pool[c->type], c);
 }
 
 int
 cbdataValid(const void *p)
 {
     cbdata *c;
-    /* Maybe NULL should be considered valid? */
     if (p == NULL)
-	return 0;
-    c = (cbdata *) hash_lookup(htable, p);
+	return 1;	/* A NULL pointer cannot become invalid */
     debug(45, 3) ("cbdataValid: %p\n", p);
-    assert(c != NULL);
+    c = (cbdata *) (((char *)p)-OFFSET_OF(cbdata,data));
+    assert(c->y == c);
     assert(c->locks > 0);
     return c->valid;
 }
 
-void
-cbdataXfree(void *p, int unused)
-{
-    xfree(p);
-}
-
-
 static void
 cbdataDump(StoreEntry * sentry)
 {
-    hash_link *hptr;
-    cbdata *c;
     storeAppendPrintf(sentry, "%d cbdata entries\n", cbdataCount);
-    hash_first(htable);
-    while ((hptr = hash_next(htable))) {
-	c = (cbdata *) hptr;
-#if CBDATA_DEBUG
-	storeAppendPrintf(sentry, "%20p %10s %d locks %s:%d\n",
-	    c->hash.key,
-	    c->valid ? "VALID" : "NOT VALID",
-	    c->locks,
-	    c->file, c->line);
-#else
-	storeAppendPrintf(sentry, "%20p %10s %d locks\n",
-	    c->hash.key,
-	    c->valid ? "VALID" : "NOT VALID",
-	    c->locks);
-#endif
-    }
+    storeAppendPrintf(sentry, "see also memory pools section\n");
 }
Index: squid/src/client_side.c
diff -u squid/src/client_side.c:1.12 squid/src/client_side.c:1.10.2.3
--- squid/src/client_side.c:1.12	Thu Jan  4 13:11:45 2001
+++ squid/src/client_side.c	Fri Jan  5 00:09:02 2001
@@ -2234,8 +2234,8 @@
 static clientHttpRequest *
 parseHttpRequestAbort(ConnStateData * conn, const char *uri)
 {
-    clientHttpRequest *http = memAllocate(MEM_CLIENTHTTPREQUEST);
-    cbdataAdd(http, memFree, MEM_CLIENTHTTPREQUEST);
+    clientHttpRequest *http;
+    http = CBDATA_ALLOC(clientHttpRequest, NULL);
     http->conn = conn;
     http->start = current_time;
     http->req_sz = conn->in.offset;
@@ -2374,8 +2374,7 @@
     assert(prefix_sz <= conn->in.offset);
 
     /* Ok, all headers are received */
-    http = memAllocate(MEM_CLIENTHTTPREQUEST);
-    cbdataAdd(http, memFree, MEM_CLIENTHTTPREQUEST);
+    http = CBDATA_ALLOC(clientHttpRequest, NULL);
     http->http_ver = http_ver;
     http->conn = conn;
     http->start = current_time;
@@ -2883,8 +2882,7 @@
 	    break;
 	}
 	debug(33, 4) ("httpAccept: FD %d: accepted\n", fd);
-	connState = memAllocate(MEM_CONNSTATEDATA);
-	cbdataAdd(connState, memFree, MEM_CONNSTATEDATA);
+	connState = CBDATA_ALLOC(ConnStateData, NULL);
 	connState->peer = peer;
 	connState->log_addr = peer.sin_addr;
 	connState->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr;
Index: squid/src/comm.c
diff -u squid/src/comm.c:1.4 squid/src/comm.c:1.4.14.1
--- squid/src/comm.c:1.4	Fri Nov  3 00:39:20 2000
+++ squid/src/comm.c	Sun Dec 17 00:20:04 2000
@@ -69,10 +69,9 @@
 static void commConnectCallback(ConnectStateData * cs, int status);
 static int commResetFD(ConnectStateData * cs);
 static int commRetryConnect(ConnectStateData * cs);
-static CBDUNL commConnectDataFree;
+CBDATA_TYPE(ConnectStateData);
 
 static MemPool *comm_write_pool = NULL;
-static MemPool *conn_state_pool = NULL;
 static MemPool *conn_close_pool = NULL;
 
 static void
@@ -231,9 +230,9 @@
 void
 commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *data)
 {
-    ConnectStateData *cs = memPoolAlloc(conn_state_pool);
+    ConnectStateData *cs;
     debug(5, 3) ("commConnectStart: FD %d, %s:%d\n", fd, host, (int) port);
-    cbdataAdd(cs, commConnectDataFree, 0);
+    cs = CBDATA_ALLOC(ConnectStateData, NULL);
     cs->fd = fd;
     cs->host = xstrdup(host);
     cs->port = port;
@@ -246,12 +245,6 @@
 }
 
 static void
-commConnectDataFree(void *data, int unused)
-{
-    memPoolFree(conn_state_pool, data);
-}
-
-static void
 commConnectDnsHandle(const ipcache_addrs * ia, void *data)
 {
     ConnectStateData *cs = data;
@@ -797,8 +790,8 @@
      * after accepting a client but before it opens a socket or a file.
      * Since Squid_MaxFD can be as high as several thousand, don't waste them */
     RESERVED_FD = XMIN(100, Squid_MaxFD / 4);
+    CBDATA_INIT_TYPE(ConnectStateData);
     comm_write_pool = memPoolCreate("CommWriteStateData", sizeof(CommWriteStateData));
-    conn_state_pool = memPoolCreate("ConnectStateData", sizeof(ConnectStateData));
     conn_close_pool = memPoolCreate("close_handler", sizeof(close_handler));
 }
 
Index: squid/src/defines.h
diff -u squid/src/defines.h:1.4 squid/src/defines.h:1.3.16.2
--- squid/src/defines.h:1.4	Wed Jan  3 23:23:59 2001
+++ squid/src/defines.h	Thu Jan  4 04:06:40 2001
@@ -282,6 +282,11 @@
 #define _PATH_DEVNULL "/dev/null"
 #endif
 
+/* cbdata macros */
+#define CBDATA_ALLOC(type, unl) ((type *)cbdataInternalAlloc(CBDATA_##type, unl))
+#define CBDATA_TYPE(type)	static cbdata_type CBDATA_##type = 0
+#define CBDATA_INIT_TYPE(type)	(CBDATA_##type = cbdataAddType(CBDATA_##type, #type, sizeof(type)))
+
 #ifndef O_TEXT
 #define O_TEXT 0
 #endif
Index: squid/src/enums.h
diff -u squid/src/enums.h:1.6 squid/src/enums.h:1.6.4.1
--- squid/src/enums.h:1.6	Tue Dec 12 15:21:18 2000
+++ squid/src/enums.h	Sun Dec 17 00:20:04 2000
@@ -675,3 +675,32 @@
     NETDB_EX_RTT,
     NETDB_EX_HOPS
 };
+
+/*
+ * cbdata types. similar to the MEM_* types above, but managed
+ * in cbdata.c. A big difference is that these types are dynamically
+ * allocated. This list is only a list of predefined types. Other types
+ * are added runtime
+ */
+typedef enum {
+    CBDATA_UNKNOWN = 0,
+    CBDATA_acl_access,
+    CBDATA_aclCheck_t,
+    CBDATA_clientHttpRequest,
+    CBDATA_ConnStateData,
+    CBDATA_DigestFetchState,
+    CBDATA_ErrorState,
+    CBDATA_FwdState,
+    CBDATA_generic_cbdata,
+    CBDATA_helper,
+    CBDATA_helper_server,
+    CBDATA_HttpStateData,
+    CBDATA_peer,
+    CBDATA_ps_state,
+    CBDATA_RemovalPolicy,
+    CBDATA_RemovalPolicyWalker,
+    CBDATA_RemovalPurgeWalker,
+    CBDATA_store_client,
+    CBDATA_storeIOState,
+    CBDATA_FIRST_CUSTOM_TYPE
+} cbdata_type;
Index: squid/src/errorpage.c
diff -u squid/src/errorpage.c:1.7 squid/src/errorpage.c:1.6.4.2
--- squid/src/errorpage.c:1.7	Wed Jan  3 23:23:59 2001
+++ squid/src/errorpage.c	Thu Jan  4 04:06:40 2001
@@ -236,7 +236,8 @@
 ErrorState *
 errorCon(err_type type, http_status status)
 {
-    ErrorState *err = memAllocate(MEM_ERRORSTATE);
+    ErrorState *err;
+    err = CBDATA_ALLOC(ErrorState, NULL);
     err->page_id = type;	/* has to be reset manually if needed */
     err->type = type;
     err->http_status = status;
@@ -340,7 +341,6 @@
 	err->request->err_type = err->type;
     /* moved in front of errorBuildBuf @?@ */
     err->flags.flag_cbdata = 1;
-    cbdataAdd(err, memFree, MEM_ERRORSTATE);
     rep = errorBuildReply(err);
     comm_write_mbuf(fd, httpReplyPack(rep), errorSendComplete, err);
     httpReplyDestroy(rep);
@@ -382,10 +382,7 @@
     wordlistDestroy(&err->ftp.server_msg);
     safe_free(err->ftp.request);
     safe_free(err->ftp.reply);
-    if (err->flags.flag_cbdata)
-	cbdataFree(err);
-    else
-	memFree(err, MEM_ERRORSTATE);
+    cbdataFree(err);
 }
 
 #define CVT_BUF_SZ 512
Index: squid/src/forward.c
diff -u squid/src/forward.c:1.6 squid/src/forward.c:1.5.4.2
--- squid/src/forward.c:1.6	Sun Dec 17 05:42:29 2000
+++ squid/src/forward.c	Thu Jan  4 04:06:41 2001
@@ -545,8 +545,7 @@
     default:
 	break;
     }
-    fwdState = memAllocate(MEM_FWD_STATE);
-    cbdataAdd(fwdState, memFree, MEM_FWD_STATE);
+    fwdState = CBDATA_ALLOC(FwdState, NULL);
     fwdState->entry = e;
     fwdState->client_fd = fd;
     fwdState->server_fd = -1;
Index: squid/src/fqdncache.c
diff -u squid/src/fqdncache.c:1.10 squid/src/fqdncache.c:1.5.4.2
--- squid/src/fqdncache.c:1.10	Sat Dec 30 20:24:34 2000
+++ squid/src/fqdncache.c	Thu Jan  4 04:06:41 2001
@@ -388,9 +388,8 @@
     f->handlerData = handlerData;
     cbdataLock(handlerData);
     f->request_time = current_time;
-    c = memAllocate(MEM_GEN_CBDATA);
+    c = CBDATA_ALLOC(generic_cbdata, NULL);
     c->data = f;
-    cbdataAdd(c, memFree, MEM_GEN_CBDATA);
 #if USE_DNSSERVERS
     dnsSubmit(hashKeyStr(&f->hash), fqdncacheHandleReply, c);
 #else
Index: squid/src/ftp.c
diff -u squid/src/ftp.c:1.5 squid/src/ftp.c:1.5.10.1
--- squid/src/ftp.c:1.5	Tue Nov 14 05:03:47 2000
+++ squid/src/ftp.c	Sun Dec 17 00:20:05 2000
@@ -1033,6 +1033,7 @@
     strcat(t, "/");
 }
 
+CBDATA_TYPE(FtpStateData);
 void
 ftpStart(FwdState * fwd)
 {
@@ -1041,11 +1042,13 @@
     int fd = fwd->server_fd;
     LOCAL_ARRAY(char, realm, 8192);
     const char *url = storeUrl(entry);
-    FtpStateData *ftpState = xcalloc(1, sizeof(FtpStateData));
+    FtpStateData *ftpState;
     HttpReply *reply;
     StoreEntry *pe = NULL;
     const cache_key *key = NULL;
-    cbdataAdd(ftpState, cbdataXfree, 0);
+
+    CBDATA_INIT_TYPE(FtpStateData);
+    ftpState=CBDATA_ALLOC(FtpStateData, NULL);
     debug(9, 3) ("ftpStart: '%s'\n", url);
     statCounter.server.all.requests++;
     statCounter.server.ftp.requests++;
Index: squid/src/gopher.c
diff -u squid/src/gopher.c:1.5 squid/src/gopher.c:1.5.4.1
--- squid/src/gopher.c:1.5	Tue Dec 12 15:21:19 2000
+++ squid/src/gopher.c	Sun Dec 17 00:20:05 2000
@@ -812,11 +812,13 @@
     commSetTimeout(fd, Config.Timeout.read, gopherTimeout, gopherState);
 }
 
+CBDATA_TYPE(GopherStateData);
 static GopherStateData *
 CreateGopherStateData(void)
 {
-    GopherStateData *gd = xcalloc(1, sizeof(GopherStateData));
-    cbdataAdd(gd, cbdataXfree, 0);
+    GopherStateData *gd;
+    CBDATA_INIT_TYPE(GopherStateData);
+    gd = CBDATA_ALLOC(GopherStateData, NULL);
     gd->buf = memAllocate(MEM_4K_BUF);
     return (gd);
 }
Index: squid/src/helper.c
diff -u squid/src/helper.c:1.3 squid/src/helper.c:1.3.16.1
--- squid/src/helper.c:1.3	Mon Oct 23 08:04:21 2000
+++ squid/src/helper.c	Sun Dec 17 00:20:05 2000
@@ -93,8 +93,7 @@
 	    continue;
 	}
 	hlp->n_running++;
-	srv = memAllocate(MEM_HELPER_SERVER);
-	cbdataAdd(srv, memFree, MEM_HELPER_SERVER);
+	srv = CBDATA_ALLOC(helper_server, NULL);
 	srv->flags.alive = 1;
 	srv->index = k;
 	srv->rfd = rfd;
@@ -224,8 +223,8 @@
 helper *
 helperCreate(const char *name)
 {
-    helper *hlp = memAllocate(MEM_HELPER);
-    cbdataAdd(hlp, memFree, MEM_HELPER);
+    helper *hlp;
+    hlp = CBDATA_ALLOC(helper, NULL);
     hlp->id_name = name;
     return hlp;
 }
Index: squid/src/http.c
diff -u squid/src/http.c:1.7 squid/src/http.c:1.5.10.3
--- squid/src/http.c:1.7	Thu Jan  4 13:11:46 2001
+++ squid/src/http.c	Fri Jan  5 00:09:02 2001
@@ -899,13 +899,13 @@
 httpStart(FwdState * fwd)
 {
     int fd = fwd->server_fd;
-    HttpStateData *httpState = memAllocate(MEM_HTTP_STATE_DATA);
+    HttpStateData *httpState;
     request_t *proxy_req;
     request_t *orig_req = fwd->request;
     debug(11, 3) ("httpStart: \"%s %s\"\n",
 	RequestMethodStr[orig_req->method],
 	storeUrl(fwd->entry));
-    cbdataAdd(httpState, memFree, MEM_HTTP_STATE_DATA);
+    httpState = CBDATA_ALLOC(HttpStateData, NULL);
     storeLockObject(fwd->entry);
     httpState->fwd = fwd;
     httpState->entry = fwd->entry;
Index: squid/src/ident.c
diff -u squid/src/ident.c:1.4 squid/src/ident.c:1.4.14.1
--- squid/src/ident.c:1.4	Fri Nov  3 00:39:20 2000
+++ squid/src/ident.c	Sun Dec 17 00:20:05 2000
@@ -178,6 +178,8 @@
     *C = c;
 }
 
+CBDATA_TYPE(IdentStateData);
+
 /**** PUBLIC FUNCTIONS ****/
 
 /*
@@ -213,8 +215,8 @@
 	callback(NULL, data);
 	return;
     }
-    state = xcalloc(1, sizeof(IdentStateData));
-    cbdataAdd(state, cbdataXfree, 0);
+    CBDATA_INIT_TYPE(IdentStateData);
+    state = CBDATA_ALLOC(IdentStateData, NULL);
     state->hash.key = xstrdup(key);
     state->fd = fd;
     state->me = *me;
Index: squid/src/ipcache.c
diff -u squid/src/ipcache.c:1.11 squid/src/ipcache.c:1.4.14.2
--- squid/src/ipcache.c:1.11	Mon Jan  1 16:02:11 2001
+++ squid/src/ipcache.c	Thu Jan  4 04:06:41 2001
@@ -433,9 +433,8 @@
     i->handlerData = handlerData;
     cbdataLock(handlerData);
     i->request_time = current_time;
-    c = memAllocate(MEM_GEN_CBDATA);
+    c = CBDATA_ALLOC(generic_cbdata, NULL);
     c->data = i;
-    cbdataAdd(c, memFree, MEM_GEN_CBDATA);
 #if USE_DNSSERVERS
     dnsSubmit(hashKeyStr(&i->hash), ipcacheHandleReply, c);
 #else
Index: squid/src/main.c
diff -u squid/src/main.c:1.13 squid/src/main.c:1.6.4.2
--- squid/src/main.c:1.13	Wed Jan  3 23:23:59 2001
+++ squid/src/main.c	Thu Jan  4 04:06:41 2001
@@ -625,11 +625,11 @@
 	if (!ConfigFile)
 	    ConfigFile = xstrdup(DefaultConfigFile);
 	assert(!configured_once);
-	memInit();		/* memInit is required for config parsing */
-	cbdataInit();
 #if USE_LEAKFINDER
 	leakInit();
 #endif
+	memInit();
+	cbdataInit();
 	eventInit();		/* eventInit() is required for config parsing */
 	storeFsInit();		/* required for config parsing */
 	parse_err = parseConfigFile(ConfigFile);
Index: squid/src/neighbors.c
diff -u squid/src/neighbors.c:1.6 squid/src/neighbors.c:1.6.4.1
--- squid/src/neighbors.c:1.6	Tue Dec 12 15:21:19 2000
+++ squid/src/neighbors.c	Sun Dec 17 00:20:05 2000
@@ -932,7 +932,7 @@
 }
 
 void
-peerDestroy(void *data, int unused)
+peerDestroy(void *data)
 {
     peer *p = data;
     struct _domain_ping *l = NULL;
@@ -952,7 +952,6 @@
 	cbdataUnlock(pd);
     }
 #endif
-    xfree(p);
 }
 
 void
@@ -1114,7 +1113,7 @@
 peerCountMcastPeersStart(void *data)
 {
     peer *p = data;
-    ps_state *psstate = xcalloc(1, sizeof(ps_state));
+    ps_state *psstate;
     StoreEntry *fake;
     MemObject *mem;
     icp_common_t *query;
@@ -1124,12 +1123,12 @@
     p->mcast.flags.count_event_pending = 0;
     snprintf(url, MAX_URL, "http://%s/", inet_ntoa(p->in_addr.sin_addr));
     fake = storeCreateEntry(url, url, null_request_flags, METHOD_GET);
+    psstate = CBDATA_ALLOC(ps_state, NULL);
     psstate->request = requestLink(urlParse(METHOD_GET, url));
     psstate->entry = fake;
     psstate->callback = NULL;
     psstate->callback_data = p;
     psstate->ping.start = current_time;
-    cbdataAdd(psstate, cbdataXfree, 0);
     mem = fake->mem_obj;
     mem->request = requestLink(psstate->request);
     mem->start_ping = current_time;
Index: squid/src/net_db.c
diff -u squid/src/net_db.c:1.7 squid/src/net_db.c:1.6.10.2
--- squid/src/net_db.c:1.7	Wed Jan  3 23:23:59 2001
+++ squid/src/net_db.c	Thu Jan  4 04:06:41 2001
@@ -223,14 +223,14 @@
 netdbSendPing(const ipcache_addrs * ia, void *data)
 {
     struct in_addr addr;
-    char *hostname = data;
+    char *hostname = ((generic_cbdata *)data)->data;
     netdbEntry *n;
     netdbEntry *na;
     net_db_name *x;
     net_db_name **X;
-    cbdataUnlock(hostname);
+    cbdataFree(data);
     if (ia == NULL) {
-	cbdataFree(hostname);
+	xfree(hostname);
 	return;
     }
     addr = ia->in_addrs[ia->cur];
@@ -248,7 +248,7 @@
 	x = (net_db_name *) hash_lookup(host_table, hostname);
 	if (x == NULL) {
 	    debug(38, 1) ("netdbSendPing: net_db_name list bug: %s not found", hostname);
-	    cbdataFree(hostname);
+	    xfree(hostname);
 	    return;
 	}
 	/* remove net_db_name from 'network n' linked list */
@@ -274,7 +274,7 @@
 	n->next_ping_time = squid_curtime + Config.Netdb.period;
 	n->last_use_time = squid_curtime;
     }
-    cbdataFree(hostname);
+    xfree(hostname);
 }
 
 static struct in_addr
@@ -678,13 +678,12 @@
 {
 #if USE_ICMP
     netdbEntry *n;
-    char *h;
+    generic_cbdata *h;
     if ((n = netdbLookupHost(hostname)) != NULL)
 	if (n->next_ping_time > squid_curtime)
 	    return;
-    h = xstrdup(hostname);
-    cbdataAdd(h, cbdataXfree, 0);
-    cbdataLock(h);
+    h = CBDATA_ALLOC(generic_cbdata, NULL);
+    h->data = xstrdup(hostname);
     ipcache_nbgethostbyname(hostname, netdbSendPing, h);
 #endif
 }
@@ -980,14 +979,19 @@
     storeComplete(s);
 }
 
+#if USE_ICMP
+CBDATA_TYPE(netdbExchangeState);
+#endif
+
 void
 netdbExchangeStart(void *data)
 {
 #if USE_ICMP
     peer *p = data;
     char *uri;
-    netdbExchangeState *ex = xcalloc(1, sizeof(*ex));
-    cbdataAdd(ex, cbdataXfree, 0);
+    netdbExchangeState *ex;
+    CBDATA_INIT_TYPE(netdbExchangeState);
+    ex = CBDATA_ALLOC(netdbExchangeState, NULL);
     cbdataLock(p);
     ex->p = p;
     uri = internalRemoteUri(p->host, p->http_port, "/squid-internal-dynamic/", "netdb");
Index: squid/src/peer_digest.c
diff -u squid/src/peer_digest.c:1.3 squid/src/peer_digest.c:1.3.16.1
--- squid/src/peer_digest.c:1.3	Mon Oct 23 08:04:21 2000
+++ squid/src/peer_digest.c	Sun Dec 17 00:20:05 2000
@@ -97,6 +97,8 @@
     stringClean(&pd->host);
 }
 
+CBDATA_TYPE(PeerDigest);
+
 /* allocate new peer digest, call Init, and lock everything */
 PeerDigest *
 peerDigestCreate(peer * p)
@@ -104,8 +106,8 @@
     PeerDigest *pd;
     assert(p);
 
-    pd = memAllocate(MEM_PEER_DIGEST);
-    cbdataAdd(pd, memFree, MEM_PEER_DIGEST);
+    CBDATA_INIT_TYPE(PeerDigest);
+    pd = CBDATA_ALLOC(PeerDigest, NULL);
     peerDigestInit(pd, p);
     cbdataLock(pd->peer);	/* we will use the peer */
 
@@ -293,8 +295,7 @@
     if (p->login)
 	xstrncpy(req->login, p->login, MAX_LOGIN_SZ);
     /* create fetch state structure */
-    fetch = memAllocate(MEM_DIGEST_FETCH_STATE);
-    cbdataAdd(fetch, memFree, MEM_DIGEST_FETCH_STATE);
+    fetch = CBDATA_ALLOC(DigestFetchState, NULL);
     fetch->request = requestLink(req);
     fetch->pd = pd;
     fetch->offset = 0;
Index: squid/src/peer_select.c
diff -u squid/src/peer_select.c:1.4 squid/src/peer_select.c:1.3.16.2
--- squid/src/peer_select.c:1.4	Mon Jan  1 16:02:11 2001
+++ squid/src/peer_select.c	Thu Jan  4 04:06:41 2001
@@ -134,12 +134,12 @@
     PSC * callback,
     void *callback_data)
 {
-    ps_state *psstate = memAllocate(MEM_PS_STATE);
+    ps_state *psstate;
     if (entry)
 	debug(44, 3) ("peerSelect: %s\n", storeUrl(entry));
     else
 	debug(44, 3) ("peerSelect: %s\n", RequestMethodStr[request->method]);
-    cbdataAdd(psstate, memFree, MEM_PS_STATE);
+    psstate = CBDATA_ALLOC(ps_state, NULL);
     psstate->request = requestLink(request);
     psstate->entry = entry;
     psstate->callback = callback;
Index: squid/src/protos.h
diff -u squid/src/protos.h:1.11 squid/src/protos.h:1.6.4.3
--- squid/src/protos.h:1.11	Thu Jan  4 13:11:46 2001
+++ squid/src/protos.h	Fri Jan  5 00:09:02 2001
@@ -86,19 +86,25 @@
 extern int GetInteger(void);
 
 
+/*
+ * cbdata.c
+ */
 extern void cbdataInit(void);
 #if CBDATA_DEBUG
-extern void cbdataAddDbg(const void *p, CBDUNL *, int, const char *, int);
+extern void * cbdataInternalAllocDbg(cbdata_type type, CBDUNL *, int, const char *);
 extern void cbdataLockDbg(const void *p, const char *, int);
 extern void cbdataUnlockDbg(const void *p, const char *, int);
 #else
-extern void cbdataAdd(const void *p, CBDUNL *, int);
+extern void * cbdataInternalAlloc(cbdata_type type, CBDUNL *);
 extern void cbdataLock(const void *p);
 extern void cbdataUnlock(const void *p);
 #endif
+/* Note: Allocations is done using the CBDATA_ALLOC macro */
+
 extern void cbdataFree(void *p);
 extern int cbdataValid(const void *p);
-extern CBDUNL cbdataXfree;
+extern void cbdataInitType(cbdata_type type, char *label, int size);
+extern cbdata_type cbdataAddType(cbdata_type type, char *label, int size);
 
 extern void clientdbInit(void);
 extern void clientdbUpdate(struct in_addr, log_type, protocol_t, size_t);
@@ -772,7 +778,7 @@
 extern void memConfigure(void);
 extern void *memAllocate(mem_type);
 extern void *memAllocBuf(size_t net_size, size_t * gross_size);
-extern CBDUNL memFree;
+extern void memFree(void *, int type);
 extern void memFreeBuf(size_t size, void *);
 extern void memFree2K(void *);
 extern void memFree4K(void *);
Index: squid/src/pump.c
diff -u squid/src/pump.c:1.4 squid/src/pump.c:1.4.14.1
--- squid/src/pump.c:1.4	Fri Nov  3 00:39:20 2000
+++ squid/src/pump.c	Sun Dec 17 00:20:05 2000
@@ -50,12 +50,13 @@
 static DEFER pumpReadDefer;
 static void pumpClose(void *data);
 
+CBDATA_TYPE(PumpStateData);
 void
 pumpInit(int fd, request_t * r, char *uri)
 {
     request_flags flags;
-    PumpStateData *p = memAllocate(MEM_PUMP_STATE_DATA);
     LOCAL_ARRAY(char, new_key, MAX_URL + 8);
+    PumpStateData *p;
     debug(61, 3) ("pumpInit: FD %d, uri=%s\n", fd, uri);
     /*
      * create a StoreEntry which will buffer the data 
@@ -70,7 +71,8 @@
     flags = null_request_flags;
     flags.nocache = 1;
     snprintf(new_key, MAX_URL + 5, "%s|Pump", uri);
-    cbdataAdd(p, memFree, MEM_PUMP_STATE_DATA);
+    CBDATA_INIT_TYPE(PumpStateData);
+    p = CBDATA_ALLOC(PumpStateData, NULL);
     p->request_entry = storeCreateEntry(new_key, new_key, flags, r->method);
     p->sc = storeClientListAdd(p->request_entry, p);
     EBIT_SET(p->request_entry->flags, ENTRY_DONT_LOG);
Index: squid/src/redirect.c
diff -u squid/src/redirect.c:1.3 squid/src/redirect.c:1.3.16.1
--- squid/src/redirect.c:1.3	Mon Oct 23 08:04:21 2000
+++ squid/src/redirect.c	Sun Dec 17 00:20:05 2000
@@ -49,6 +49,7 @@
 static helper *redirectors = NULL;
 static OBJH redirectStats;
 static int n_bypassed = 0;
+CBDATA_TYPE(redirectStateData);
 
 static void
 redirectHandleReply(void *data, char *reply)
@@ -122,8 +123,7 @@
 	handler(data, NULL);
 	return;
     }
-    r = xcalloc(1, sizeof(redirectStateData));
-    cbdataAdd(r, cbdataXfree, 0);
+    r = CBDATA_ALLOC(redirectStateData, NULL);
     r->orig_url = xstrdup(http->uri);
     r->client_addr = conn->log_addr;
     if (http->request->user_ident[0])
@@ -165,6 +165,7 @@
 	    "URL Redirector Stats",
 	    redirectStats, 0, 1);
 	init = 1;
+	CBDATA_INIT_TYPE(redirectStateData);
     }
 }
 
Index: squid/src/send-announce.c
diff -u squid/src/send-announce.c:1.4 squid/src/send-announce.c:1.3.16.2
--- squid/src/send-announce.c:1.4	Wed Jan  3 23:23:59 2001
+++ squid/src/send-announce.c	Thu Jan  4 04:06:41 2001
@@ -40,13 +40,11 @@
 void
 start_announce(void *datanotused)
 {
-    void *junk;
     if (0 == Config.onoff.announce)
 	return;
     if (theOutIcpConnection < 0)
 	return;
-    cbdataAdd(junk = xmalloc(1), cbdataXfree, 0);
-    ipcache_nbgethostbyname(Config.Announce.host, send_announce, junk);
+    ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL);
     eventAdd("send_announce", start_announce, NULL, (double) Config.Announce.period, 1);
 }
 
@@ -63,7 +61,6 @@
     int n;
     int fd;
     int x;
-    cbdataFree(junk);
     if (ia == NULL) {
 	debug(27, 1) ("send_announce: Unknown host '%s'\n", host);
 	return;
Index: squid/src/squid.h
diff -u squid/src/squid.h:1.4 squid/src/squid.h:1.3.16.2
--- squid/src/squid.h:1.4	Wed Jan  3 23:23:59 2001
+++ squid/src/squid.h	Thu Jan  4 04:06:41 2001
@@ -318,7 +318,7 @@
 #endif
 
 #if CBDATA_DEBUG
-#define cbdataAdd(a,b,c)	cbdataAddDbg(a,b,c,__FILE__,__LINE__)
+#define cbdataAlloc(a,b)	cbdataAllocDbg(a,b,__FILE__,__LINE__)
 #define cbdataLock(a)		cbdataLockDbg(a,__FILE__,__LINE__)
 #define cbdataUnlock(a)		cbdataUnlockDbg(a,__FILE__,__LINE__)
 #endif
@@ -432,3 +432,4 @@
 #define INDEXSD(i)   (&Config.cacheSwap.swapDirs[(i)])
 
 #endif /* SQUID_H */
+#define CREATE_CBDATA(type) cbdataInitType(CBDATA_##type, #type, sizeof(type))
Index: squid/src/ssl.c
diff -u squid/src/ssl.c:1.3 squid/src/ssl.c:1.3.16.1
--- squid/src/ssl.c:1.3	Mon Oct 23 08:04:22 2000
+++ squid/src/ssl.c	Sun Dec 17 00:20:05 2000
@@ -429,6 +429,7 @@
     }
 }
 
+CBDATA_TYPE(SslStateData);
 void
 sslStart(int fd, const char *url, request_t * request, size_t * size_ptr, int *status_ptr)
 {
@@ -482,8 +483,8 @@
 	errorSend(fd, err);
 	return;
     }
-    sslState = xcalloc(1, sizeof(SslStateData));
-    cbdataAdd(sslState, cbdataXfree, 0);
+    CBDATA_INIT_TYPE(SslStateData);
+    sslState = CBDATA_ALLOC(SslStateData, NULL);
 #if DELAY_POOLS
     sslState->delay_id = delayClient(request);
     delayRegisterDelayIdPtr(&sslState->delay_id);
Index: squid/src/stat.c
diff -u squid/src/stat.c:1.4 squid/src/stat.c:1.4.14.1
--- squid/src/stat.c:1.4	Fri Nov  3 00:39:20 2000
+++ squid/src/stat.c	Sun Dec 17 00:20:05 2000
@@ -88,6 +88,7 @@
 static int NCountHist = 0;
 static StatCounters CountHourHist[N_COUNT_HOUR_HIST];
 static int NCountHourHist = 0;
+CBDATA_TYPE(StatObjectsState);
 
 extern unsigned int mem_pool_alloc_calls;
 extern unsigned int mem_pool_free_calls;
@@ -343,11 +344,11 @@
 static void
 statObjectsStart(StoreEntry * sentry, STOBJFLT * filter)
 {
-    StatObjectsState *state = xcalloc(1, sizeof(*state));
+    StatObjectsState *state;
+    state = CBDATA_ALLOC(StatObjectsState, NULL);
     state->sentry = sentry;
     state->filter = filter;
     storeLockObject(sentry);
-    cbdataAdd(state, cbdataXfree, 0);
     eventAdd("statObjects", statObjects, state, 0.0, 1);
 }
 
@@ -832,6 +833,7 @@
 {
     int i;
     debug(18, 5) ("statInit: Initializing...\n");
+    CBDATA_INIT_TYPE(StatObjectsState);
     for (i = 0; i < N_COUNT_HIST; i++)
 	statCountersInit(&CountHist[i]);
     for (i = 0; i < N_COUNT_HOUR_HIST; i++)
Index: squid/src/store_client.c
diff -u squid/src/store_client.c:1.4 squid/src/store_client.c:1.4.14.1
--- squid/src/store_client.c:1.4	Fri Nov  3 00:39:20 2000
+++ squid/src/store_client.c	Sun Dec 17 00:20:05 2000
@@ -133,8 +133,7 @@
 #endif
     e->refcount++;
     mem->nclients++;
-    sc = memAllocate(MEM_STORE_CLIENT);
-    cbdataAdd(sc, memFree, MEM_STORE_CLIENT);	/* sc is callback_data for file_read */
+    sc = CBDATA_ALLOC(store_client, NULL);
     cbdataLock(data);		/* locked while we point to it */
     sc->callback_data = data;
     sc->seen_offset = 0;
Index: squid/src/store_digest.c
diff -u squid/src/store_digest.c:1.5 squid/src/store_digest.c:1.5.10.1
--- squid/src/store_digest.c:1.5	Tue Nov 14 05:03:47 2000
+++ squid/src/store_digest.c	Sun Dec 17 00:20:05 2000
@@ -51,7 +51,7 @@
 typedef struct {
     StoreDigestCBlock cblock;
     int rebuild_lock;		/* bucket number */
-    StoreEntry *rewrite_lock;	/* store entry with the digest */
+    generic_cbdata *rewrite_lock;	/* points to store entry with the digest */
     int rebuild_offset;
     int rewrite_offset;
     int rebuild_count;
@@ -350,9 +350,10 @@
     url = internalLocalUri("/squid-internal-periodic/", StoreDigestFileName);
     flags = null_request_flags;
     flags.cachable = 1;
-    sd_state.rewrite_lock = e = storeCreateEntry(url, url, flags, METHOD_GET);
-    assert(sd_state.rewrite_lock);
-    cbdataAdd(sd_state.rewrite_lock, NULL, 0);
+    e = storeCreateEntry(url, url, flags, METHOD_GET);
+    assert(e);
+    sd_state.rewrite_lock = CBDATA_ALLOC(generic_cbdata, NULL);
+    sd_state.rewrite_lock->data = e;
     debug(71, 3) ("storeDigestRewrite: url: %s key: %s\n", url, storeKeyText(e->hash.key));
     e->mem_obj->request = requestLink(urlParse(METHOD_GET, url));
     /* wait for rebuild (if any) to finish */
@@ -366,11 +367,12 @@
 static void
 storeDigestRewriteResume(void)
 {
-    StoreEntry *e = sd_state.rewrite_lock;
+    StoreEntry *e;
     http_version_t version;
 
     assert(sd_state.rewrite_lock);
     assert(!sd_state.rebuild_lock);
+    e = sd_state.rewrite_lock->data;
     sd_state.rewrite_offset = 0;
     EBIT_SET(e->flags, ENTRY_SPECIAL);
     /* setting public key will purge old digest entry if any */
@@ -394,7 +396,7 @@
 static void
 storeDigestRewriteFinish(StoreEntry * e)
 {
-    assert(e == sd_state.rewrite_lock);
+    assert(sd_state.rewrite_lock && e == sd_state.rewrite_lock->data);
     storeComplete(e);
     storeTimestampsSet(e);
     debug(71, 2) ("storeDigestRewriteFinish: digest expires at %d (%+d)\n",
@@ -403,10 +405,6 @@
     requestUnlink(e->mem_obj->request);
     e->mem_obj->request = NULL;
     storeUnlockObject(e);
-    /*
-     * note, it won't really get free()'d here because we used
-     * MEM_DONTFREE in the call to cbdataAdd().
-     */
     cbdataFree(sd_state.rewrite_lock);
     sd_state.rewrite_lock = e = NULL;
     sd_state.rewrite_count++;
@@ -421,10 +419,11 @@
 static void
 storeDigestSwapOutStep(void *data)
 {
-    StoreEntry *e = data;
+    StoreEntry *e;
     int chunk_size = Config.digest.swapout_chunk_size;
+    assert(data == sd_state.rewrite_lock);
+    e = (StoreEntry *)((generic_cbdata *)data)->data;
     assert(e);
-    assert(e == sd_state.rewrite_lock);
     /* _add_ check that nothing bad happened while we were waiting @?@ @?@ */
     if (sd_state.rewrite_offset + chunk_size > store_digest->mask_size)
 	chunk_size = store_digest->mask_size - sd_state.rewrite_offset;
@@ -436,7 +435,7 @@
     if (sd_state.rewrite_offset >= store_digest->mask_size)
 	storeDigestRewriteFinish(e);
     else
-	eventAdd("storeDigestSwapOutStep", storeDigestSwapOutStep, e, 0.0, 1);
+	eventAdd("storeDigestSwapOutStep", storeDigestSwapOutStep, data, 0.0, 1);
 }
 
 static void
Index: squid/src/store_swapout.c
diff -u squid/src/store_swapout.c:1.4 squid/src/store_swapout.c:1.4.14.1
--- squid/src/store_swapout.c:1.4	Fri Nov  3 00:39:20 2000
+++ squid/src/store_swapout.c	Sun Dec 17 00:20:05 2000
@@ -61,9 +61,8 @@
     storeSwapTLVFree(tlv_list);
     mem->swap_hdr_sz = (size_t) swap_hdr_sz;
     /* Create the swap file */
-    c = memAllocate(MEM_GEN_CBDATA);
+    c = CBDATA_ALLOC(generic_cbdata, NULL);
     c->data = e;
-    cbdataAdd(c, memFree, MEM_GEN_CBDATA);
     mem->swapout.sio = storeCreate(e, storeSwapOutFileNotify, storeSwapOutFileClosed, c);
     if (NULL == mem->swapout.sio) {
 	e->swap_status = SWAPOUT_NONE;
Index: squid/src/typedefs.h
diff -u squid/src/typedefs.h:1.5 squid/src/typedefs.h:1.4.10.2
--- squid/src/typedefs.h:1.5	Thu Jan  4 13:11:46 2001
+++ squid/src/typedefs.h	Fri Jan  5 00:09:02 2001
@@ -195,7 +195,7 @@
 typedef void CNCB(int fd, int status, void *);
 
 typedef void FREE(void *);
-typedef void CBDUNL(void *, int);
+typedef void CBDUNL(void *);
 typedef void FOCB(void *, int fd, int errcode);
 typedef void EVH(void *);
 typedef void PF(int, void *);
Index: squid/src/urn.c
diff -u squid/src/urn.c:1.5 squid/src/urn.c:1.5.4.1
--- squid/src/urn.c:1.5	Tue Dec 12 15:21:20 2000
+++ squid/src/urn.c	Sun Dec 17 00:20:05 2000
@@ -95,6 +95,7 @@
     return min_u;
 }
 
+CBDATA_TYPE(UrnState);
 void
 urnStart(request_t * r, StoreEntry * e)
 {
@@ -106,10 +107,10 @@
     StoreEntry *urlres_e;
     ErrorState *err;
     debug(52, 3) ("urnStart: '%s'\n", storeUrl(e));
-    urnState = xcalloc(1, sizeof(UrnState));
+    CBDATA_INIT_TYPE(UrnState);
+    urnState = CBDATA_ALLOC(UrnState, NULL);
     urnState->entry = e;
     urnState->request = requestLink(r);
-    cbdataAdd(urnState, cbdataXfree, 0);
     storeLockObject(urnState->entry);
     if (strncasecmp(strBuf(r->urlpath), "menu.", 5) == 0) {
 	char *new_path = xstrdup(strBuf(r->urlpath) + 5);
Index: squid/src/wais.c
diff -u squid/src/wais.c:1.3 squid/src/wais.c:1.3.16.1
--- squid/src/wais.c:1.3	Mon Oct 23 08:04:22 2000
+++ squid/src/wais.c	Sun Dec 17 00:20:05 2000
@@ -216,6 +216,7 @@
     EBIT_CLR(waisState->entry->flags, ENTRY_FWD_HDR_WAIT);
 }
 
+CBDATA_TYPE(WaisStateData);
 void
 waisStart(FwdState * fwd)
 {
@@ -228,8 +229,8 @@
     debug(24, 3) ("waisStart: \"%s %s\"\n", RequestMethodStr[method], url);
     statCounter.server.all.requests++;
     statCounter.server.other.requests++;
-    waisState = xcalloc(1, sizeof(WaisStateData));
-    cbdataAdd(waisState, cbdataXfree, 0);
+    CBDATA_INIT_TYPE(WaisStateData);
+    waisState = CBDATA_ALLOC(WaisStateData, NULL);
     waisState->method = method;
     waisState->request_hdr = &request->header;
     waisState->fd = fd;
Index: squid/src/whois.c
diff -u squid/src/whois.c:1.3 squid/src/whois.c:1.3.16.1
--- squid/src/whois.c:1.3	Mon Oct 23 08:04:22 2000
+++ squid/src/whois.c	Sun Dec 17 00:20:05 2000
@@ -49,17 +49,20 @@
 
 /* PUBLIC */
 
+CBDATA_TYPE(WhoisState);
+
 void
 whoisStart(FwdState * fwd)
 {
-    WhoisState *p = xcalloc(1, sizeof(*p));
+    WhoisState *p;
     int fd = fwd->server_fd;
     char *buf;
     size_t l;
+    CBDATA_INIT_TYPE(WhoisState);
+    p = CBDATA_ALLOC(WhoisState, NULL);
     p->request = fwd->request;
     p->entry = fwd->entry;
     p->fwd = fwd;
-    cbdataAdd(p, cbdataXfree, 0);
     storeLockObject(p->entry);
     comm_add_close_handler(fd, whoisClose, p);
     l = strLen(p->request->urlpath) + 3;
Index: squid/src/fs/aufs/store_dir_aufs.c
diff -u squid/src/fs/aufs/store_dir_aufs.c:1.8 squid/src/fs/aufs/store_dir_aufs.c:1.6.4.3
--- squid/src/fs/aufs/store_dir_aufs.c:1.8	Thu Jan  4 22:38:08 2001
+++ squid/src/fs/aufs/store_dir_aufs.c	Fri Jan  5 00:09:02 2001
@@ -820,14 +820,18 @@
     return e;
 }
 
+CBDATA_TYPE(RebuildState);
+
 static void
 storeAufsDirRebuild(SwapDir * sd)
 {
-    RebuildState *rb = xcalloc(1, sizeof(*rb));
+    RebuildState *rb;
     int clean = 0;
     int zero = 0;
     FILE *fp;
     EVH *func = NULL;
+    CBDATA_INIT_TYPE(RebuildState);
+    rb = CBDATA_ALLOC(RebuildState, NULL);
     rb->sd = sd;
     rb->speed = opt_foreground_rebuild ? 1 << 30 : 50;
     /*
@@ -851,7 +855,6 @@
     debug(20, 1) ("Rebuilding storage in %s (%s)\n",
 	sd->path, clean ? "CLEAN" : "DIRTY");
     store_dirs_rebuilding++;
-    cbdataAdd(rb, cbdataXfree, 0);
     eventAdd("storeRebuild", func, rb, 0.0, 1);
 }
 
Index: squid/src/fs/aufs/store_io_aufs.c
diff -u squid/src/fs/aufs/store_io_aufs.c:1.4 squid/src/fs/aufs/store_io_aufs.c:1.3.12.3
--- squid/src/fs/aufs/store_io_aufs.c:1.4	Wed Jan  3 23:24:00 2001
+++ squid/src/fs/aufs/store_io_aufs.c	Thu Jan  4 04:06:41 2001
@@ -20,7 +20,7 @@
 static AIOCB storeAufsOpenDone;
 static int storeAufsSomethingPending(storeIOState *);
 static int storeAufsKickWriteQueue(storeIOState * sio);
-static void storeAufsIOFreeEntry(void *, int);
+static CBDUNL storeAufsIOFreeEntry;
 
 /* === PUBLIC =========================================================== */
 
@@ -51,8 +51,7 @@
 	return NULL;
     }
 #endif
-    sio = memAllocate(MEM_STORE_IO);
-    cbdataAdd(sio, storeAufsIOFreeEntry, MEM_STORE_IO);
+    sio = CBDATA_ALLOC(storeIOState, storeAufsIOFreeEntry);
     sio->fsstate = memPoolAlloc(aio_state_pool);
     ((aiostate_t *) (sio->fsstate))->fd = -1;
     ((aiostate_t *) (sio->fsstate))->flags.opening = 1;
@@ -106,8 +105,7 @@
 	return NULL;
     }
 #endif
-    sio = memAllocate(MEM_STORE_IO);
-    cbdataAdd(sio, storeAufsIOFreeEntry, MEM_STORE_IO);
+    sio = CBDATA_ALLOC(storeIOState, storeAufsIOFreeEntry);
     sio->fsstate = memPoolAlloc(aio_state_pool);
     ((aiostate_t *) (sio->fsstate))->fd = -1;
     ((aiostate_t *) (sio->fsstate))->flags.opening = 1;
@@ -453,12 +451,12 @@
 
 
 /*      
- * We can't pass memFree() as a free function here, because we need to free
- * the fsstate variable ..
+ * Clean up references from the SIO before it gets released.
+ * The actuall SIO is managed by cbdata so we do not need
+ * to bother with that.
  */
 static void
-storeAufsIOFreeEntry(void *sio, int foo)
+storeAufsIOFreeEntry(void *sio)
 {
     memPoolFree(aio_state_pool, ((storeIOState *) sio)->fsstate);
-    memFree(sio, MEM_STORE_IO);
 }
Index: squid/src/fs/coss/store_dir_coss.c
diff -u squid/src/fs/coss/store_dir_coss.c:1.6 squid/src/fs/coss/store_dir_coss.c:1.4.4.3
--- squid/src/fs/coss/store_dir_coss.c:1.6	Thu Jan  4 22:38:08 2001
+++ squid/src/fs/coss/store_dir_coss.c	Fri Jan  5 00:09:02 2001
@@ -42,7 +42,6 @@
 int n_coss_dirs = 0;
 /* static int last_coss_pick_index = -1; */
 int coss_initialised = 0;
-MemPool *coss_membuf_pool = NULL;
 MemPool *coss_state_pool = NULL;
 MemPool *coss_index_pool = NULL;
 
@@ -327,15 +326,17 @@
     return e;
 }
 
+CBDATA_TYPE(RebuildState);
 static void
 storeCossDirRebuild(SwapDir * sd)
 {
-    RebuildState *rb = xcalloc(1, sizeof(*rb));
+    RebuildState *rb;
     int clean = 0;
     int zero = 0;
     FILE *fp;
     EVH *func = NULL;
-    cbdataAdd(rb, cbdataXfree, 0);
+    CBDATA_INIT_TYPE(RebuildState);
+    rb = CBDATA_ALLOC(RebuildState, NULL);
     rb->sd = sd;
     rb->speed = opt_foreground_rebuild ? 1 << 30 : 50;
     func = storeCossRebuildFromSwapLog;
@@ -858,7 +859,6 @@
 static void
 storeCossDirDone(void)
 {
-    memPoolDestroy(coss_membuf_pool);
     memPoolDestroy(coss_state_pool);
     coss_initialised = 0;
 }
@@ -871,7 +871,6 @@
     storefs->parsefunc = storeCossDirParse;
     storefs->reconfigurefunc = storeCossDirReconfigure;
     storefs->donefunc = storeCossDirDone;
-    coss_membuf_pool = memPoolCreate("COSS Membuf data", sizeof(CossMemBuf));
     coss_state_pool = memPoolCreate("COSS IO State data", sizeof(CossState));
     coss_index_pool = memPoolCreate("COSS index data", sizeof(CossIndexNode));
     coss_initialised = 1;
Index: squid/src/fs/coss/store_io_coss.c
diff -u squid/src/fs/coss/store_io_coss.c:1.3 squid/src/fs/coss/store_io_coss.c:1.2.18.2
--- squid/src/fs/coss/store_io_coss.c:1.3	Wed Jan  3 23:24:00 2001
+++ squid/src/fs/coss/store_io_coss.c	Thu Jan  4 04:06:42 2001
@@ -46,8 +46,8 @@
 static void storeCossWriteMemBufDone(int fd, int errflag, size_t len, void *my_data);
 static CossMemBuf *storeCossCreateMemBuf(SwapDir * SD, size_t start,
     sfileno curfn, int *collision);
-static void storeCossIOFreeEntry(void *, int);
-static void storeCossMembufFree(void *, int);
+static CBDUNL storeCossIOFreeEntry;
+static CBDUNL storeCossMembufFree;
 
 /* === PUBLIC =========================================================== */
 
@@ -128,8 +128,7 @@
     CossState *cstate;
     storeIOState *sio;
 
-    sio = memAllocate(MEM_STORE_IO);
-    cbdataAdd(sio, storeCossIOFreeEntry, MEM_STORE_IO);
+    sio = CBDATA_ALLOC(storeIOState, storeCossIOFreeEntry);
     cstate = memPoolAlloc(coss_state_pool);
     sio->fsstate = cstate;
     sio->offset = 0;
@@ -173,8 +172,7 @@
 
     debug(81, 3) ("storeCossOpen: offset %d\n", f);
 
-    sio = memAllocate(MEM_STORE_IO);
-    cbdataAdd(sio, storeCossIOFreeEntry, MEM_STORE_IO);
+    sio = CBDATA_ALLOC(storeIOState, storeCossIOFreeEntry);
     cstate = memPoolAlloc(coss_state_pool);
 
     sio->fsstate = cstate;
@@ -432,7 +430,6 @@
     CossInfo *cs = (CossInfo *) SD->fsdata;
     debug(81, 3) ("storeCossWriteMemBuf: offset %d, len %d\n",
 	t->diskstart, t->diskend - t->diskstart);
-    cbdataAdd(t, storeCossMembufFree, 0);
     t->flags.writing = 1;
     file_write(cs->fd, t->diskstart, &t->buffer,
 	t->diskend - t->diskstart, storeCossWriteMemBufDone, t, NULL);
@@ -469,6 +466,7 @@
     cbdataFree(t);
 }
 
+CBDATA_TYPE(CossMemBuf);
 static CossMemBuf *
 storeCossCreateMemBuf(SwapDir * SD, size_t start,
     sfileno curfn, int *collision)
@@ -479,7 +477,8 @@
     int numreleased = 0;
     CossInfo *cs = (CossInfo *) SD->fsdata;
 
-    newmb = memPoolAlloc(coss_membuf_pool);
+    CBDATA_INIT_TYPE(CossMemBuf);
+    newmb = CBDATA_ALLOC(CossMemBuf, storeCossMembufFree);
     newmb->diskstart = start;
     debug(81, 3) ("storeCossCreateMemBuf: creating new membuf at %d\n", newmb->diskstart);
     newmb->diskend = newmb->diskstart + COSS_MEMBUF_SZ - 1;
@@ -530,7 +529,7 @@
  * the fsstate variable ..
  */
 static void
-storeCossIOFreeEntry(void *sio, int foo)
+storeCossIOFreeEntry(void *sio)
 {
     memPoolFree(coss_state_pool, ((storeIOState *) sio)->fsstate);
     memFree(sio, MEM_STORE_IO);
@@ -542,7 +541,7 @@
  * So we have this hack here ..
  */
 static void
-storeCossMembufFree(void *mb, int foo)
+storeCossMembufFree(void *mb)
 {
-    memPoolFree(coss_membuf_pool, mb);
+    cbdataFree(mb);
 }
Index: squid/src/fs/diskd/store_dir_diskd.c
diff -u squid/src/fs/diskd/store_dir_diskd.c:1.7 squid/src/fs/diskd/store_dir_diskd.c:1.5.4.3
--- squid/src/fs/diskd/store_dir_diskd.c:1.7	Thu Jan  4 22:38:08 2001
+++ squid/src/fs/diskd/store_dir_diskd.c	Fri Jan  5 00:09:03 2001
@@ -1011,14 +1011,18 @@
     return e;
 }
 
+CBDATA_TYPE(RebuildState);
+
 static void
 storeDiskdDirRebuild(SwapDir * sd)
 {
-    RebuildState *rb = xcalloc(1, sizeof(*rb));
+    RebuildState *rb;
     int clean = 0;
     int zero = 0;
     FILE *fp;
     EVH *func = NULL;
+    CBDATA_INIT_TYPE(RebuildState);
+    rb = CBDATA_ALLOC(RebuildState, NULL);
     rb->sd = sd;
     rb->speed = opt_foreground_rebuild ? 1 << 30 : 50;
     /*
@@ -1042,7 +1046,6 @@
     debug(20, 1) ("Rebuilding storage in %s (%s)\n",
 	sd->path, clean ? "CLEAN" : "DIRTY");
     store_dirs_rebuilding++;
-    cbdataAdd(rb, cbdataXfree, 0);
     eventAdd("storeRebuild", func, rb, 0.0, 1);
 }
 
Index: squid/src/fs/diskd/store_io_diskd.c
diff -u squid/src/fs/diskd/store_io_diskd.c:1.4 squid/src/fs/diskd/store_io_diskd.c:1.3.6.2
--- squid/src/fs/diskd/store_io_diskd.c:1.4	Wed Jan  3 23:24:00 2001
+++ squid/src/fs/diskd/store_io_diskd.c	Thu Jan  4 04:06:42 2001
@@ -44,7 +44,7 @@
 
 static int storeDiskdSend(int, SwapDir *, int, storeIOState *, int, int, int);
 static void storeDiskdIOCallback(storeIOState * sio, int errflag);
-static void storeDiskdIOFreeEntry(void *sio, int foo);
+static CBDUNL storeDiskdIOFreeEntry;
 
 /* === PUBLIC =========================================================== */
 
@@ -68,8 +68,7 @@
 	diskd_stats.open_fail_queue_len++;
 	return NULL;
     }
-    sio = memAllocate(MEM_STORE_IO);
-    cbdataAdd(sio, storeDiskdIOFreeEntry, MEM_STORE_IO);
+    sio = CBDATA_ALLOC(storeIOState, storeDiskdIOFreeEntry);
     sio->fsstate = diskdstate = memPoolAlloc(diskd_state_pool);
 
     sio->swap_filen = f;
@@ -127,8 +126,7 @@
     f = storeDiskdDirMapBitAllocate(SD);
     debug(81, 3) ("storeDiskdCreate: fileno %08X\n", f);
 
-    sio = memAllocate(MEM_STORE_IO);
-    cbdataAdd(sio, storeDiskdIOFreeEntry, MEM_STORE_IO);
+    sio = CBDATA_ALLOC(storeIOState, storeDiskdIOFreeEntry);
     sio->fsstate = diskdstate = memPoolAlloc(diskd_state_pool);
 
     sio->swap_filen = f;
@@ -519,8 +517,7 @@
  * the fsstate variable ..
  */
 static void
-storeDiskdIOFreeEntry(void *sio, int foo)
+storeDiskdIOFreeEntry(void *sio)
 {
     memPoolFree(diskd_state_pool, ((storeIOState *) sio)->fsstate);
-    memFree(sio, MEM_STORE_IO);
 }
Index: squid/src/fs/ufs/store_dir_ufs.c
diff -u squid/src/fs/ufs/store_dir_ufs.c:1.7 squid/src/fs/ufs/store_dir_ufs.c:1.5.4.3
--- squid/src/fs/ufs/store_dir_ufs.c:1.7	Thu Jan  4 22:38:09 2001
+++ squid/src/fs/ufs/store_dir_ufs.c	Fri Jan  5 00:09:03 2001
@@ -818,14 +818,17 @@
     return e;
 }
 
+CBDATA_TYPE(RebuildState);
 static void
 storeUfsDirRebuild(SwapDir * sd)
 {
-    RebuildState *rb = xcalloc(1, sizeof(*rb));
+    RebuildState *rb;
     int clean = 0;
     int zero = 0;
     FILE *fp;
     EVH *func = NULL;
+    CBDATA_INIT_TYPE(RebuildState);
+    rb = CBDATA_ALLOC(RebuildState, NULL);
     rb->sd = sd;
     rb->speed = opt_foreground_rebuild ? 1 << 30 : 50;
     /*
@@ -849,7 +852,6 @@
     debug(20, 1) ("Rebuilding storage in %s (%s)\n",
 	sd->path, clean ? "CLEAN" : "DIRTY");
     store_dirs_rebuilding++;
-    cbdataAdd(rb, cbdataXfree, 0);
     eventAdd("storeRebuild", func, rb, 0.0, 1);
 }
 
Index: squid/src/fs/ufs/store_io_ufs.c
diff -u squid/src/fs/ufs/store_io_ufs.c:1.3 squid/src/fs/ufs/store_io_ufs.c:1.2.18.3
--- squid/src/fs/ufs/store_io_ufs.c:1.3	Wed Jan  3 23:24:01 2001
+++ squid/src/fs/ufs/store_io_ufs.c	Thu Jan  4 04:06:42 2001
@@ -40,7 +40,7 @@
 static DRCB storeUfsReadDone;
 static DWCB storeUfsWriteDone;
 static void storeUfsIOCallback(storeIOState * sio, int errflag);
-static void storeUfsIOFreeEntry(void *, int);
+static CBDUNL storeUfsIOFreeEntry;
 
 /* === PUBLIC =========================================================== */
 
@@ -60,8 +60,7 @@
 	return NULL;
     }
     debug(79, 3) ("storeUfsOpen: opened FD %d\n", fd);
-    sio = memAllocate(MEM_STORE_IO);
-    cbdataAdd(sio, storeUfsIOFreeEntry, MEM_STORE_IO);
+    sio = CBDATA_ALLOC(storeIOState, storeUfsIOFreeEntry);
     sio->fsstate = memPoolAlloc(ufs_state_pool);
 
     sio->swap_filen = f;
@@ -108,8 +107,7 @@
 	return NULL;
     }
     debug(79, 3) ("storeUfsCreate: opened FD %d\n", fd);
-    sio = memAllocate(MEM_STORE_IO);
-    cbdataAdd(sio, storeUfsIOFreeEntry, MEM_STORE_IO);
+    sio = CBDATA_ALLOC(storeIOState, storeUfsIOFreeEntry);
     sio->fsstate = memPoolAlloc(ufs_state_pool);
 
     sio->swap_filen = filn;
@@ -257,12 +255,10 @@
 
 
 /*
- * We can't pass memFree() as a free function here, because we need to free
- * the fsstate variable ..
+ * Clean up any references from the SIO before it get's released.
  */
 static void
-storeUfsIOFreeEntry(void *sio, int foo)
+storeUfsIOFreeEntry(void *sio)
 {
     memPoolFree(ufs_state_pool, ((storeIOState *) sio)->fsstate);
-    memFree(sio, MEM_STORE_IO);
 }
Index: squid/src/repl/heap/store_repl_heap.c
diff -u squid/src/repl/heap/store_repl_heap.c:1.3 squid/src/repl/heap/store_repl_heap.c:1.3.14.1
--- squid/src/repl/heap/store_repl_heap.c:1.3	Fri Nov  3 13:04:27 2000
+++ squid/src/repl/heap/store_repl_heap.c	Sun Dec 17 00:20:06 2000
@@ -151,14 +151,13 @@
     RemovalPolicyWalker *walker;
     HeapWalkData *heap_walk;
     heap->nwalkers += 1;
-    walker = xcalloc(1, sizeof(*walker));
+    walker = CBDATA_ALLOC(RemovalPolicyWalker, NULL);
     heap_walk = xcalloc(1, sizeof(*heap_walk));
     heap_walk->current = 0;
     walker->_policy = policy;
     walker->_data = heap_walk;
     walker->Next = heap_walkNext;
     walker->Done = heap_walkDone;
-    cbdataAdd(walker, cbdataXfree, 0);
     return walker;
 }
 
@@ -225,7 +224,7 @@
     RemovalPurgeWalker *walker;
     HeapPurgeData *heap_walk;
     heap->nwalkers += 1;
-    walker = xcalloc(1, sizeof(*walker));
+    walker = CBDATA_ALLOC(RemovalPurgeWalker, NULL);
     heap_walk = xcalloc(1, sizeof(*heap_walk));
     heap_walk->min_age = 0.0;
     heap_walk->locked_entries = NULL;
@@ -234,7 +233,6 @@
     walker->max_scan = max_scan;
     walker->Next = heap_purgeNext;
     walker->Done = heap_purgeDone;
-    cbdataAdd(walker, cbdataXfree, 0);
 #if HEAP_REPLACEMENT_DEBUG
     if (!verify_heap_property(heap->heap)) {
 	debug(81, 1) ("Heap property violated!\n");
@@ -264,10 +262,8 @@
     HeapPolicyData *heap_data;
     char *keytype;
     /* Allocate the needed structures */
-    policy = xcalloc(1, sizeof(*policy));
+    policy = CBDATA_ALLOC(RemovalPolicy, NULL);
     heap_data = xcalloc(1, sizeof(*heap_data));
-    /* cbdata register the policy */
-    cbdataAdd(policy, cbdataXfree, 0);
     /* Initialize the policy data */
     heap_data->policy = policy;
     if (args) {
Index: squid/src/repl/lru/store_repl_lru.c
diff -u squid/src/repl/lru/store_repl_lru.c:1.2 squid/src/repl/lru/store_repl_lru.c:1.2.18.1
--- squid/src/repl/lru/store_repl_lru.c:1.2	Sat Oct 21 09:44:46 2000
+++ squid/src/repl/lru/store_repl_lru.c	Sun Dec 17 00:20:06 2000
@@ -162,14 +162,13 @@
     RemovalPolicyWalker *walker;
     LruWalkData *lru_walk;
     lru->nwalkers += 1;
-    walker = xcalloc(1, sizeof(*walker));
+    walker=CBDATA_ALLOC(RemovalPolicyWalker, NULL);
     lru_walk = xcalloc(1, sizeof(*lru_walk));
     walker->_policy = policy;
     walker->_data = lru_walk;
     walker->Next = lru_walkNext;
     walker->Done = lru_walkDone;
     lru_walk->current = (LruNode *) lru->list.head;
-    cbdataAdd(walker, cbdataXfree, 0);
     return walker;
 }
 
@@ -232,7 +231,7 @@
     RemovalPurgeWalker *walker;
     LruPurgeData *lru_walk;
     lru->nwalkers += 1;
-    walker = xcalloc(1, sizeof(*walker));
+    walker=CBDATA_ALLOC(RemovalPurgeWalker, NULL);
     lru_walk = xcalloc(1, sizeof(*lru_walk));
     walker->_policy = policy;
     walker->_data = lru_walk;
@@ -240,7 +239,6 @@
     walker->Next = lru_purgeNext;
     walker->Done = lru_purgeDone;
     lru_walk->start = lru_walk->current = (LruNode *) lru->list.head;
-    cbdataAdd(walker, cbdataXfree, 0);
     return walker;
 }
 
@@ -269,10 +267,8 @@
     if (!lru_node_pool)
 	lru_node_pool = memPoolCreate("LRU policy node", sizeof(LruNode));
     /* Allocate the needed structures */
-    policy = xcalloc(1, sizeof(*policy));
     lru_data = xcalloc(1, sizeof(*lru_data));
-    /* cbdata register the policy */
-    cbdataAdd(policy, cbdataXfree, 0);
+    policy=CBDATA_ALLOC(RemovalPolicy, NULL);
     /* Initialize the URL data */
     lru_data->policy = policy;
     /* Populate the policy structure */
squid-cbdata-20010105-HEAD.new squid-cbdata-20010105-HEAD differ: char 74, line 2
