r22629: if irpc gets freed within event_loop_once() we crash...
authorStefan Metzmacher <metze@samba.org>
Tue, 1 May 2007 09:55:36 +0000 (09:55 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:51:56 +0000 (14:51 -0500)
so deferr the freeing

metze
(This used to be commit 3a30bc0d6137fe2b7440106b35dd0a9175cc8057)

source4/lib/messaging/irpc.h
source4/lib/messaging/messaging.c

index 1d704ad943f63249f6a9fa768b3770c8a4fedf20..6873f014a6a9fbe9b78db80639664e8d50bd85a4 100644 (file)
@@ -69,6 +69,7 @@ struct irpc_request {
        void *r;
        NTSTATUS status;
        BOOL done;
+       BOOL reject_free;
        TALLOC_CTX *mem_ctx;
        struct {
                void (*fn)(struct irpc_request *);
index 04b340eb5a12b86de8edbeae610a397af8faf186..705fdcc4655d6e9ce4a9c13505594aa870c5e9c7 100644 (file)
@@ -773,7 +773,14 @@ failed:
 */
 static int irpc_destructor(struct irpc_request *irpc)
 {
-       idr_remove(irpc->msg_ctx->idr, irpc->callid);
+       if (irpc->callid != -1) {
+               idr_remove(irpc->msg_ctx->idr, irpc->callid);
+               irpc->callid = -1;
+       }
+
+       if (irpc->reject_free) {
+               return -1;
+       }
        return 0;
 }
 
@@ -866,11 +873,16 @@ NTSTATUS irpc_call_recv(struct irpc_request *irpc)
 
        NT_STATUS_HAVE_NO_MEMORY(irpc);
 
+       irpc->reject_free = true;
+
        while (!irpc->done) {
                if (event_loop_once(irpc->msg_ctx->event.ev) != 0) {
                        return NT_STATUS_CONNECTION_DISCONNECTED;
                }
        }
+
+       irpc->reject_free = false;
+
        status = irpc->status;
        talloc_free(irpc);
        return status;