From 8301410c799501ab87c2b829e0be3717ad999b19 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 11 May 2015 22:02:35 +0300 Subject: [PATCH] Fixed possible memory leaks in schemarouter. --- .../routing/schemarouter/schemarouter.c | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/modules/routing/schemarouter/schemarouter.c b/server/modules/routing/schemarouter/schemarouter.c index c31a3b975..cf60bae51 100644 --- a/server/modules/routing/schemarouter/schemarouter.c +++ b/server/modules/routing/schemarouter/schemarouter.c @@ -1164,9 +1164,9 @@ static void closeSession( dcb_close(router_cli_ses->dcb_reply); dcb_close(router_cli_ses->dcb_route); - if(router_cli_ses->queue) - router_cli_ses->queue = gwbuf_consume( - router_cli_ses->queue,gwbuf_length(router_cli_ses->queue)); + while(router_cli_ses->queue && + (router_cli_ses->queue = gwbuf_consume( + router_cli_ses->queue,gwbuf_length(router_cli_ses->queue)))); /** Unlock */ rses_end_locked_router_action(router_cli_ses); @@ -1195,18 +1195,17 @@ static void freeSession( ROUTER_CLIENT_SES* router_cli_ses; ROUTER_INSTANCE* router; int i; - backend_ref_t* backend_ref; + backend_ref_t* bref; router_cli_ses = (ROUTER_CLIENT_SES *)router_client_session; router = (ROUTER_INSTANCE *)router_instance; - backend_ref = router_cli_ses->rses_backend_ref; for (i=0; irses_nbackends; i++) { - if (!BREF_IS_IN_USE((&backend_ref[i]))) - { - continue; - } + bref = &router_cli_ses->rses_backend_ref[i]; + while(bref->bref_pending_cmd && + (bref->bref_pending_cmd = gwbuf_consume( + bref->bref_pending_cmd,gwbuf_length(bref->bref_pending_cmd)))); } spinlock_acquire(&router->lock); @@ -2237,7 +2236,8 @@ static int routeQuery( */ if (sescmd_cursor_is_active(scur)) { - ss_dassert(bref->bref_pending_cmd == NULL); + ss_dassert((bref->bref_pending_cmd == NULL || + router_cli_ses->rses_closed)); bref->bref_pending_cmd = gwbuf_clone(querybuf); rses_end_locked_router_action(router_cli_ses);