summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-17 11:37:22 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:58 -0500
commit53891ed37e32a97380430e6911878f3b94133e01 (patch)
treea50cdbcc809f3182e34a5b948326cf0c20e8e59e
parent6591a226144d371a6b68fc5e7201a90a77dc9153 (diff)
downloadsamba-53891ed37e32a97380430e6911878f3b94133e01.tar.gz
samba-53891ed37e32a97380430e6911878f3b94133e01.tar.bz2
samba-53891ed37e32a97380430e6911878f3b94133e01.zip
r3017: nicer memory handling for event_context_merge()
(This used to be commit 1cef44505e5de9b8ae5206522b624082ad2343b2)
-rw-r--r--source4/include/events.h3
-rw-r--r--source4/lib/events.c25
-rw-r--r--source4/libcli/raw/clitransport.c1
-rw-r--r--source4/ntvfs/cifs/vfs_cifs.c4
4 files changed, 14 insertions, 19 deletions
diff --git a/source4/include/events.h b/source4/include/events.h
index edded2632b..c44acc77ae 100644
--- a/source4/include/events.h
+++ b/source4/include/events.h
@@ -68,7 +68,8 @@ struct event_context {
int code;
} exit;
- int ref_count;
+ /* we hang the events off here, to make merging easy */
+ void *events;
};
diff --git a/source4/lib/events.c b/source4/lib/events.c
index 0e98b42503..2cedfc083c 100644
--- a/source4/lib/events.c
+++ b/source4/lib/events.c
@@ -81,7 +81,7 @@ struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
/* start off with no events */
ZERO_STRUCTP(ev);
- ev->ref_count = 1;
+ ev->events = talloc(ev, 0);
return ev;
}
@@ -91,11 +91,6 @@ struct event_context *event_context_init(TALLOC_CTX *mem_ctx)
*/
void event_context_destroy(struct event_context *ev)
{
- ev->ref_count--;
- if (ev->ref_count != 0) {
- return;
- }
-
talloc_free(ev);
}
@@ -121,18 +116,18 @@ static void calc_maxfd(struct event_context *ev)
this is used by modules that need to call on the events of a lower module
*/
-struct event_context * event_context_merge(struct event_context *ev, struct event_context *ev2)
+struct event_context *event_context_merge(struct event_context *ev, struct event_context *ev2)
{
DLIST_CONCATENATE(ev->fd_events, ev2->fd_events, struct fd_event *);
DLIST_CONCATENATE(ev->timed_events, ev2->timed_events, struct timed_event *);
DLIST_CONCATENATE(ev->loop_events, ev2->loop_events, struct loop_event *);
- ev->ref_count++;
-
ev2->fd_events = NULL;
ev2->timed_events = NULL;
ev2->loop_events = NULL;
+ talloc_steal(ev->events, ev2->events);
+
event_context_destroy(ev2);
calc_maxfd(ev);
@@ -147,7 +142,7 @@ struct event_context * event_context_merge(struct event_context *ev, struct even
*/
struct fd_event *event_add_fd(struct event_context *ev, struct fd_event *e)
{
- e = talloc_memdup(ev, e, sizeof(*e));
+ e = talloc_memdup(ev->events, e, sizeof(*e));
if (!e) return NULL;
DLIST_ADD(ev->fd_events, e);
e->ref_count = 1;
@@ -217,7 +212,7 @@ void event_remove_fd_all_handler(struct event_context *ev, void *handler)
*/
struct timed_event *event_add_timed(struct event_context *ev, struct timed_event *e)
{
- e = talloc_memdup(ev, e, sizeof(*e));
+ e = talloc_memdup(ev->events, e, sizeof(*e));
if (!e) return NULL;
e->ref_count = 1;
DLIST_ADD(ev->timed_events, e);
@@ -246,7 +241,7 @@ BOOL event_remove_timed(struct event_context *ev, struct timed_event *e1)
*/
struct loop_event *event_add_loop(struct event_context *ev, struct loop_event *e)
{
- e = talloc_memdup(ev, e, sizeof(*e));
+ e = talloc_memdup(ev->events, e, sizeof(*e));
if (!e) return NULL;
e->ref_count = 1;
DLIST_ADD(ev->loop_events, e);
@@ -302,7 +297,7 @@ int event_loop_once(struct event_context *ev)
struct loop_event *next = le->next;
if (le->ref_count == 0) {
DLIST_REMOVE(ev->loop_events, le);
- talloc_unlink(ev, le);
+ talloc_unlink(ev->events, le);
} else {
le->ref_count++;
le->handler(ev, le, t);
@@ -323,7 +318,7 @@ int event_loop_once(struct event_context *ev)
if (ev->maxfd == fe->fd) {
ev->maxfd = EVENT_INVALID_MAXFD;
}
- talloc_unlink(ev, fe);
+ talloc_unlink(ev->events, fe);
} else {
if (fe->flags & EVENT_FD_READ) {
FD_SET(fe->fd, &r_fds);
@@ -404,7 +399,7 @@ int event_loop_once(struct event_context *ev)
struct timed_event *next = te->next;
if (te->ref_count == 0) {
DLIST_REMOVE(ev->timed_events, te);
- talloc_unlink(ev, te);
+ talloc_unlink(ev->events, te);
} else if (te->next_event <= t) {
te->ref_count++;
te->handler(ev, te, t);
diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c
index 3944afb638..c84c025c74 100644
--- a/source4/libcli/raw/clitransport.c
+++ b/source4/libcli/raw/clitransport.c
@@ -51,7 +51,6 @@ static int transport_destructor(void *ptr)
smbcli_transport_dead(transport);
event_remove_fd(transport->event.ctx, transport->event.fde);
event_remove_timed(transport->event.ctx, transport->event.te);
- event_context_destroy(transport->event.ctx);
return 0;
}
diff --git a/source4/ntvfs/cifs/vfs_cifs.c b/source4/ntvfs/cifs/vfs_cifs.c
index 65a7c7a206..7c4a1d79d6 100644
--- a/source4/ntvfs/cifs/vfs_cifs.c
+++ b/source4/ntvfs/cifs/vfs_cifs.c
@@ -138,7 +138,6 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
private->transport = private->tree->session->transport;
private->tree->session->pid = SVAL(req->in.hdr, HDR_PID);
private->tcon = req->tcon;
- /*private->ops = ntvfs_backend_byname("cifs", NTVFS_DISK);*/
tcon->fs_type = talloc_strdup(tcon, "NTFS");
tcon->dev_type = talloc_strdup(tcon, "A:");
@@ -151,7 +150,8 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
private->transport->event.fde->private = private;
private->transport->event.ctx = event_context_merge(tcon->smb_conn->connection->event.ctx,
- private->transport->event.ctx);
+ private->transport->event.ctx);
+ talloc_reference(private, private->transport->event.ctx);
return NT_STATUS_OK;
}