1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

s4:lib/messaging: fix interaction between imessaging_context_destructor and irpc_destructor

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15280

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
Stefan Metzmacher 2022-12-31 01:24:57 +01:00
parent c29c487c5a
commit 0d09693119
2 changed files with 16 additions and 0 deletions

View File

@ -48,6 +48,7 @@
a pending irpc call a pending irpc call
*/ */
struct irpc_request { struct irpc_request {
struct irpc_request *prev, *next;
struct imessaging_context *msg_ctx; struct imessaging_context *msg_ctx;
int callid; int callid;
struct { struct {
@ -400,6 +401,16 @@ NTSTATUS imessaging_process_cleanup(
static int imessaging_context_destructor(struct imessaging_context *msg) static int imessaging_context_destructor(struct imessaging_context *msg)
{ {
struct irpc_request *irpc = NULL;
struct irpc_request *next = NULL;
for (irpc = msg->requests; irpc != NULL; irpc = next) {
next = irpc->next;
DLIST_REMOVE(msg->requests, irpc);
irpc->callid = -1;
}
DLIST_REMOVE(msg_ctxs, msg); DLIST_REMOVE(msg_ctxs, msg);
TALLOC_FREE(msg->msg_dgm_ref); TALLOC_FREE(msg->msg_dgm_ref);
return 0; return 0;
@ -1035,6 +1046,7 @@ failed:
static int irpc_destructor(struct irpc_request *irpc) static int irpc_destructor(struct irpc_request *irpc)
{ {
if (irpc->callid != -1) { if (irpc->callid != -1) {
DLIST_REMOVE(irpc->msg_ctx->requests, irpc);
idr_remove(irpc->msg_ctx->idr, irpc->callid); idr_remove(irpc->msg_ctx->idr, irpc->callid);
if (irpc->msg_ctx->discard_incoming) { if (irpc->msg_ctx->discard_incoming) {
SMB_ASSERT(irpc->msg_ctx->num_incoming_listeners > 0); SMB_ASSERT(irpc->msg_ctx->num_incoming_listeners > 0);
@ -1238,6 +1250,7 @@ static struct tevent_req *irpc_bh_raw_call_send(TALLOC_CTX *mem_ctx,
/* make sure we accept incoming messages */ /* make sure we accept incoming messages */
SMB_ASSERT(state->irpc->msg_ctx->num_incoming_listeners < UINT64_MAX); SMB_ASSERT(state->irpc->msg_ctx->num_incoming_listeners < UINT64_MAX);
state->irpc->msg_ctx->num_incoming_listeners += 1; state->irpc->msg_ctx->num_incoming_listeners += 1;
DLIST_ADD_END(state->irpc->msg_ctx->requests, state->irpc);
talloc_set_destructor(state->irpc, irpc_destructor); talloc_set_destructor(state->irpc, irpc_destructor);
/* setup the header */ /* setup the header */

View File

@ -19,6 +19,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
struct irpc_request;
struct imessaging_context { struct imessaging_context {
struct imessaging_context *prev, *next; struct imessaging_context *prev, *next;
struct tevent_context *ev; struct tevent_context *ev;
@ -30,6 +32,7 @@ struct imessaging_context {
struct idr_context *dispatch_tree; struct idr_context *dispatch_tree;
struct irpc_list *irpc; struct irpc_list *irpc;
struct idr_context *idr; struct idr_context *idr;
struct irpc_request *requests;
struct server_id_db *names; struct server_id_db *names;
struct timeval start_time; struct timeval start_time;
void *msg_dgm_ref; void *msg_dgm_ref;