[SCM] Samba Shared Repository - branch v3-3-test updated - release-3-2-0pre2-3568-g3d4e7b2

Volker Lendecke vlendec at samba.org
Sun Aug 10 16:41:32 GMT 2008


The branch, v3-3-test has been updated
       via  3d4e7b29c235e329aaea4fa2c2078df0ce3e59eb (commit)
      from  af2b01d85188d2301580643f7e862e3e3988aadc (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-3-test


- Log -----------------------------------------------------------------
commit 3d4e7b29c235e329aaea4fa2c2078df0ce3e59eb
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Aug 9 21:39:18 2008 +0200

    Make events robust against their event_context being freed

-----------------------------------------------------------------------

Summary of changes:
 source/lib/events.c |   33 ++++++++++++++++++++++++++++-----
 1 files changed, 28 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/lib/events.c b/source/lib/events.c
index 7750176..f031387 100644
--- a/source/lib/events.c
+++ b/source/lib/events.c
@@ -63,7 +63,9 @@ static int timed_event_destructor(struct timed_event *te)
 {
 	DEBUG(10, ("Destroying timed event %lx \"%s\"\n", (unsigned long)te,
 		te->event_name));
-	DLIST_REMOVE(te->event_ctx->timed_events, te);
+	if (te->event_ctx != NULL) {
+		DLIST_REMOVE(te->event_ctx->timed_events, te);
+	}
 	return 0;
 }
 
@@ -131,9 +133,9 @@ struct timed_event *event_add_timed(struct event_context *event_ctx,
 
 static int fd_event_destructor(struct fd_event *fde)
 {
-	struct event_context *event_ctx = fde->event_ctx;
-
-	DLIST_REMOVE(event_ctx->fd_events, fde);
+	if (fde->event_ctx != NULL) {
+		DLIST_REMOVE(fde->event_ctx->fd_events, fde);
+	}
 	return 0;
 }
 
@@ -354,9 +356,30 @@ int event_loop_once(struct event_context *ev)
 	return 0;
 }
 
+static int event_context_destructor(struct event_context *ev)
+{
+	while (ev->fd_events != NULL) {
+		ev->fd_events->event_ctx = NULL;
+		DLIST_REMOVE(ev->fd_events, ev->fd_events);
+	}
+	while (ev->timed_events != NULL) {
+		ev->timed_events->event_ctx = NULL;
+		DLIST_REMOVE(ev->timed_events, ev->timed_events);
+	}
+	return 0;
+}
+
 struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
 {
-	return TALLOC_ZERO_P(mem_ctx, struct event_context);
+	struct event_context *result;
+
+	result = TALLOC_ZERO_P(mem_ctx, struct event_context);
+	if (result == NULL) {
+		return NULL;
+	}
+
+	talloc_set_destructor(result, event_context_destructor);
+	return result;
 }
 
 int set_event_dispatch_time(struct event_context *event_ctx,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list