diff options
| author | Stefan Metzmacher <metze@samba.org> | 2013-09-27 03:41:29 +0200 |
|---|---|---|
| committer | Stefan Metzmacher <metze@samba.org> | 2014-01-17 12:38:08 +0100 |
| commit | 0ed93e099af833045d9d00b9a8faeb5b93b6ef2e (patch) | |
| tree | 4d79362476c3b6f3e772d2220f04ecb0902f6d67 /lib/tevent | |
| parent | 7502a309e8b817036c1ddc38740c214ae416bf29 (diff) | |
| download | samba-0ed93e099af833045d9d00b9a8faeb5b93b6ef2e.tar.gz samba-0ed93e099af833045d9d00b9a8faeb5b93b6ef2e.tar.xz samba-0ed93e099af833045d9d00b9a8faeb5b93b6ef2e.zip | |
tevent: add/use tevent_req_destructor
This makes sure we call tevent_req_received(req) on talloc_free()
and cleanup things in a defined order.
Note that some callers used their own destructor for their
tevent_req instance, they'll just overwrite this,
which is not intended, but works without problems.
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'lib/tevent')
| -rw-r--r-- | lib/tevent/tevent_req.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/tevent/tevent_req.c b/lib/tevent/tevent_req.c index edb8550072..30e91e2526 100644 --- a/lib/tevent/tevent_req.c +++ b/lib/tevent/tevent_req.c @@ -51,6 +51,8 @@ char *tevent_req_print(TALLOC_CTX *mem_ctx, struct tevent_req *req) return req->private_print(req, mem_ctx); } +static int tevent_req_destructor(struct tevent_req *req); + struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx, void *pdata, size_t data_size, @@ -86,10 +88,18 @@ struct tevent_req *_tevent_req_create(TALLOC_CTX *mem_ctx, req->data = data; + talloc_set_destructor(req, tevent_req_destructor); + *ppdata = data; return req; } +static int tevent_req_destructor(struct tevent_req *req) +{ + tevent_req_received(req); + return 0; +} + void _tevent_req_notify_callback(struct tevent_req *req, const char *location) { req->internal.finish_location = location; @@ -200,7 +210,8 @@ bool tevent_req_is_in_progress(struct tevent_req *req) void tevent_req_received(struct tevent_req *req) { - TALLOC_FREE(req->data); + talloc_set_destructor(req, NULL); + req->private_print = NULL; req->private_cancel = NULL; @@ -208,6 +219,8 @@ void tevent_req_received(struct tevent_req *req) TALLOC_FREE(req->internal.timer); req->internal.state = TEVENT_REQ_RECEIVED; + + TALLOC_FREE(req->data); } bool tevent_req_poll(struct tevent_req *req, |
