]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
eventAdd, eventRun, et al. now check cbdata before making a callback.
authorwessels <>
Wed, 13 May 1998 02:16:32 +0000 (02:16 +0000)
committerwessels <>
Wed, 13 May 1998 02:16:32 +0000 (02:16 +0000)
If the 'arg' pointer becomes invalid, then the event is NOT run.
Events with NULL 'arg's are always run.

src/cbdata.cc
src/enums.h
src/event.cc
src/mem.cc
src/store_digest.cc

index a2906eb8aeffd6bf7208cd3e5e76ce9644114e41..cb49ce78716915816e5777f3fbcf896a95f1ebee 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cbdata.cc,v 1.19 1998/03/31 05:37:36 wessels Exp $
+ * $Id: cbdata.cc,v 1.20 1998/05/12 20:16:32 wessels Exp $
  *
  * DEBUG: section 45    Callback Data Registry
  * AUTHOR: Duane Wessels
@@ -137,6 +137,8 @@ cbdataReallyFree(cbdata * c)
     hash_remove_link(htable, (hash_link *) c);
     cbdataCount--;
     xfree(c);
+    if (mem_type == MEM_DONTFREE)
+       return;
     debug(45, 3) ("cbdataReallyFree: Freeing %p\n", p);
     if (mem_type == MEM_NONE)
        xfree(p);
index a667cf867d922816327047e14405a1dc1c1eb2ef..2ede3a92f74a6921fe48fc464ed9fa1e693d2135 100644 (file)
@@ -506,6 +506,7 @@ enum {
 
 typedef enum {
     MEM_NONE,
+    MEM_DONTFREE,
     MEM_DISK_BUF,
     MEM_STMEM_BUF,
     MEM_4K_BUF,
index 344415528047cdfb385012bf52721059b0a6f3c4..efdc8c1cbd98c092e4a3c906f7efc56c8a96f9e2 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: event.cc,v 1.13 1998/04/06 22:32:14 wessels Exp $
+ * $Id: event.cc,v 1.14 1998/05/12 20:16:33 wessels Exp $
  *
  * DEBUG: section 41    Event Processing
  * AUTHOR: Henrik Nordstrom
@@ -52,6 +52,8 @@ eventAdd(const char *name, EVH * func, void *arg, time_t when)
     event->arg = arg;
     event->name = name;
     event->when = squid_curtime + when;
+    if (NULL != arg)
+        cbdataLock(arg);
     debug(41, 7) ("eventAdd: Adding '%s', in %d seconds\n", name, (int) when);
     /* Insert after the last event with the same or earlier time */
     for (E = &tasks; *E; E = &(*E)->next) {
@@ -84,6 +86,8 @@ eventDelete(EVH * func, void *arg)
        if (event->arg != arg)
            continue;
        *E = event->next;
+       if (NULL != event->arg)
+           cbdataUnlock(event->arg);
        xfree(event);
        return;
     }
@@ -100,13 +104,19 @@ eventRun(void)
        return;
     if (event->when > squid_curtime)
        return;
-    debug(41, 7) ("eventRun: Running '%s'\n", event->name);
     func = event->func;
     arg = event->arg;
     event->func = NULL;
     event->arg = NULL;
     tasks = event->next;
     safe_free(event);
+    if (NULL != arg) {
+        int valid = cbdataValid(arg);
+        cbdataUnlock(arg);
+        if (!valid)
+           return;
+    }
+    debug(41, 7) ("eventRun: Running '%s'\n", event->name);
     func(arg);
 }
 
index 79ff6e5dcda558608a4faf68b1c5a0ee3ea228e2..62ee03c28cf72d90e89f37280e03e66e543c3f8e 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: mem.cc,v 1.22 1998/04/24 07:09:37 wessels Exp $
+ * $Id: mem.cc,v 1.23 1998/05/12 20:16:34 wessels Exp $
  *
  * DEBUG: section 13    High Level Memory Pool Management
  * AUTHOR: Harvest Derived
@@ -272,6 +272,8 @@ memInit(void)
     memDataInit(MEM_CLIENT_INFO, "ClientInfo", sizeof(ClientInfo), 0);
     /* test that all entries are initialized */
     for (t = MEM_NONE + 1; t < MEM_MAX; t++) {
+       if (MEM_DONTFREE == t)
+               continue;
        /*
         * If you hit this assertion, then you forgot to add a
         * memDataInit() line for type 't' above.
index ecfa7e9a9ffd9a2f907d8f2d0d90c5ef00c65126..47caaabb50ad86cdd758c28d2fa804c6cd4c00ae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: store_digest.cc,v 1.13 1998/05/05 23:02:50 wessels Exp $
+ * $Id: store_digest.cc,v 1.14 1998/05/12 20:16:34 wessels Exp $
  *
  * DEBUG: section 71    Store Digest Manager
  * AUTHOR: Alex Rousskov
@@ -263,6 +263,7 @@ storeDigestRewriteStart(void *datanotused)
     EBIT_SET(flags, REQ_CACHABLE);
     sd_state.rewrite_lock = e = storeCreateEntry(url, url, flags, METHOD_GET);
     assert(sd_state.rewrite_lock);
+    cbdataAdd(sd_state.rewrite_lock, MEM_DONTFREE);
     debug(71, 3) ("storeDigestRewrite: url: %s key: %s\n", url, storeKeyText(e->key));
     e->mem_obj->request = requestLink(urlParse(METHOD_GET, url));
     /* wait for rebuild (if any) to finish */
@@ -310,6 +311,11 @@ storeDigestRewriteFinish(StoreEntry * e)
     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++;
     eventAdd("storeDigestRewriteStart", storeDigestRewriteStart, NULL, StoreDigestRewritePeriod);