From bc939501e9cf567d93b0b40dab3b7897129cb14a Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 1 Sep 2014 10:11:04 +0300 Subject: [PATCH] minor bugfix to memory allocations --- .../routing/readwritesplit/readwritesplit.c | 118 +++++++++--------- 1 file changed, 62 insertions(+), 56 deletions(-) diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 72fe0c03a..ba4f70489 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -1377,83 +1377,89 @@ static int routeQuery( strcpy(hkey,dbname); strcat(hkey,"."); strcat(hkey,tbl[0]); - } + } - if(tsize > 0){ - for(i = 0;irses_prop_chk_top = CHK_NUM_ROUTER_PROPERTY; - rses_prop_tmp->rses_prop_chk_tail = CHK_NUM_ROUTER_PROPERTY; + rses_prop_tmp->rses_prop_chk_top = CHK_NUM_ROUTER_PROPERTY; + rses_prop_tmp->rses_prop_chk_tail = CHK_NUM_ROUTER_PROPERTY; #endif - rses_prop_tmp->rses_prop_rsession = router_cli_ses; - rses_prop_tmp->rses_prop_refcount = 1; - rses_prop_tmp->rses_prop_next = NULL; - rses_prop_tmp->rses_prop_type = RSES_PROP_TYPE_TMPTABLES; - router_cli_ses->rses_properties[RSES_PROP_TYPE_TMPTABLES] = rses_prop_tmp; + rses_prop_tmp->rses_prop_rsession = router_cli_ses; + rses_prop_tmp->rses_prop_refcount = 1; + rses_prop_tmp->rses_prop_next = NULL; + rses_prop_tmp->rses_prop_type = RSES_PROP_TYPE_TMPTABLES; + router_cli_ses->rses_properties[RSES_PROP_TYPE_TMPTABLES] = rses_prop_tmp; + } + } - } + if( rses_prop_tmp->rses_prop_data.temp_tables == NULL){ - if( rses_prop_tmp->rses_prop_data.temp_tables == NULL){ - - h = hashtable_alloc(7, hashkeyfun, hashcmpfun); - hashtable_memory_fns(h,hstrdup,NULL,hfree,NULL); - if(h){ - rses_prop_tmp->rses_prop_data.temp_tables = h; + h = hashtable_alloc(7, hashkeyfun, hashcmpfun); + hashtable_memory_fns(h,hstrdup,NULL,hfree,NULL); + if(h){ + rses_prop_tmp->rses_prop_data.temp_tables = h; + } + } - } - - if( - hashtable_add( - rses_prop_tmp->rses_prop_data.temp_tables, - (void *)hkey, - (void *)is_temp - ) - == 0) /**Conflict in hash table*/ - { - LOGIF(LT, (skygw_log_write( - LOGFILE_TRACE, - "Temporary table conflict in hashtable: %s",hkey))); - } -#if defined(SS_DEBUG) - bool retkey = hashtable_fetch( - rses_prop_tmp->rses_prop_data.temp_tables, - hkey); - if(retkey){ + if( + hashtable_add( + rses_prop_tmp->rses_prop_data.temp_tables, + (void *)hkey, + (void *)is_temp + ) + == 0) /**Conflict in hash table*/ + { LOGIF(LT, (skygw_log_write( LOGFILE_TRACE, - "Temporary table added: %s",hkey))); + "Temporary table conflict in hashtable: %s",hkey))); } + +#if defined(SS_DEBUG) + bool retkey = hashtable_fetch( + rses_prop_tmp->rses_prop_data.temp_tables, + hkey); + if(retkey){ + LOGIF(LT, (skygw_log_write( + LOGFILE_TRACE, + "Temporary table added: %s",hkey))); + } #endif + + } + + /**Check if DROP TABLE... targets a temporary table*/ + if(QUERY_IS_TYPE(qtype, QUERY_TYPE_DROP_TABLE)) + { + if(rses_prop_tmp && rses_prop_tmp->rses_prop_data.temp_tables) + { + hashtable_delete(rses_prop_tmp->rses_prop_data.temp_tables, (void *)hkey); + } + } + + free(hkey); + + if(tsize > 0) + { + for(i = 0;irses_prop_data.temp_tables){ - hashtable_delete(rses_prop_tmp->rses_prop_data.temp_tables, (void *)hkey); - } } - free(hkey); - if (master_dcb == NULL) { succp = get_dcb(&master_dcb, router_cli_ses, BE_MASTER);