diff --git a/query_classifier/query_classifier.cc b/query_classifier/query_classifier.cc index eccc35a31..889940e00 100644 --- a/query_classifier/query_classifier.cc +++ b/query_classifier/query_classifier.cc @@ -149,17 +149,17 @@ skygw_query_type_t skygw_query_classifier_get_type( thd = get_or_create_thd_for_parsing(mysql, query_str); if (thd == NULL) - { - skygw_query_classifier_free(mysql); - } - /** Create parse_tree inside thd */ - failp = create_parse_tree(thd); - - if (failp) { skygw_query_classifier_free(mysql); *p_mysql = NULL; + goto return_qtype; } + /** + * Create parse_tree inside thd. + * thd and even lex are readable even if parser failed so let it + * continue despite failure. + */ + failp = create_parse_tree(thd); qtype = resolve_query_type(thd); if (p_mysql == NULL) @@ -464,7 +464,7 @@ static skygw_query_type_t resolve_query_type( type |= QUERY_TYPE_DISABLE_AUTOCOMMIT; type |= QUERY_TYPE_BEGIN_TRX; } - /** + /** * REVOKE ALL, ASSIGN_TO_KEYCACHE, * PRELOAD_KEYS, FLUSH, RESET, CREATE|ALTER|DROP SERVER */ diff --git a/server/core/session.c b/server/core/session.c index 80767f9ff..62e1015e4 100644 --- a/server/core/session.c +++ b/server/core/session.c @@ -667,6 +667,7 @@ int i; session->filters[i].session = head->session; session->filters[i].instance = head->instance; session->head = *head; + free(head); } for (i = 0; i < service->n_filters; i++) diff --git a/server/modules/include/mysql_client_server_protocol.h b/server/modules/include/mysql_client_server_protocol.h index f7d6030c1..9e2147d05 100644 --- a/server/modules/include/mysql_client_server_protocol.h +++ b/server/modules/include/mysql_client_server_protocol.h @@ -299,6 +299,7 @@ typedef struct { void gw_mysql_close(MySQLProtocol **ptr); MySQLProtocol* mysql_protocol_init(DCB* dcb, int fd); +void mysql_protocol_done (DCB* dcb); MySQLProtocol *gw_mysql_init(MySQLProtocol *data); void gw_mysql_close(MySQLProtocol **ptr); int gw_receive_backend_auth(MySQLProtocol *protocol); diff --git a/server/modules/protocol/mysql_backend.c b/server/modules/protocol/mysql_backend.c index 43cd97bcd..5d8088d4e 100644 --- a/server/modules/protocol/mysql_backend.c +++ b/server/modules/protocol/mysql_backend.c @@ -996,6 +996,8 @@ gw_backend_close(DCB *dcb) /** Send COM_QUIT to the backend being closed */ mysql_send_com_quit(dcb, 0, quitbuf); + + mysql_protocol_done(dcb); if (session != NULL && session->state == SESSION_STATE_STOPPING) { diff --git a/server/modules/protocol/mysql_client.c b/server/modules/protocol/mysql_client.c index db61084eb..6cc9027de 100644 --- a/server/modules/protocol/mysql_client.c +++ b/server/modules/protocol/mysql_client.c @@ -1325,6 +1325,7 @@ gw_client_close(DCB *dcb) CHK_PROTOCOL(protocol); } #endif + mysql_protocol_done(dcb); session = dcb->session; /** diff --git a/server/modules/protocol/mysql_common.c b/server/modules/protocol/mysql_common.c index 4ce34452b..70050a13c 100644 --- a/server/modules/protocol/mysql_common.c +++ b/server/modules/protocol/mysql_common.c @@ -96,6 +96,31 @@ return_p: } +/** + * mysql_protocol_done + * + * free protocol allocations. + * + * @param dcb owner DCB + * + */ +void mysql_protocol_done ( + DCB* dcb) +{ + server_command_t* scmd = ((MySQLProtocol *)dcb->protocol)->protocol_cmd_history; + server_command_t* scmd2; + + while (scmd != NULL) + { + scmd2 = scmd->scom_next; + free(scmd); + scmd = scmd2; + } +} + + + + /** * gw_mysql_close * @@ -1601,7 +1626,7 @@ void protocol_archive_srv_command( { server_command_t* s1; server_command_t** s2; - int len; + int len = 0; spinlock_acquire(&p->protocol_lock); @@ -1617,9 +1642,7 @@ void protocol_archive_srv_command( s2 = &p->protocol_cmd_history; if (*s2 != NULL) - { - len = 0; - + { while ((*s2)->scom_next != NULL) { *s2 = (*s2)->scom_next; diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 90132a9f9..7fcf22974 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -1132,6 +1132,8 @@ static int routeQuery( break; case MYSQL_COM_STMT_EXECUTE: + /** Parsing is not needed for this type of packet */ +#if defined(NOT_USED) plainsqlbuf = gwbuf_clone_transform(querybuf, GWBUF_TYPE_PLAINSQL); len = GWBUF_LENGTH(plainsqlbuf); @@ -1140,7 +1142,8 @@ static int routeQuery( memcpy(querystr, startpos, len); memset(&querystr[len], 0, 1); qtype = skygw_query_classifier_get_type(querystr, 0, &mysql); - qtype |= QUERY_TYPE_EXEC_STMT; +#endif + qtype = QUERY_TYPE_EXEC_STMT; break; case MYSQL_COM_SHUTDOWN: /**< 8 where should shutdown be routed ? */ @@ -1923,7 +1926,8 @@ static bool select_connect_backend_servers( } } } - } + } /*< log only */ + /** * Choose at least 1+min_nslaves (master and slave) and at most 1+max_nslaves * servers from the sorted list. First master found is selected. @@ -2666,8 +2670,9 @@ static bool execute_sescmd_in_backend( pthread_self(), dcb->fd, STRPACKETTYPE(cmd)))); + gwbuf_free(tmpbuf); } -#endif +#endif /*< SS_DEBUG */ switch (scur->scmd_cur_cmd->my_sescmd_packet_type) { case MYSQL_COM_CHANGE_USER: rc = dcb->func.auth( @@ -3065,7 +3070,7 @@ static bool router_option_configured( } return succp; } -#endif +#endif /*< NOT_USED */ static void rwsplit_process_router_options( ROUTER_INSTANCE* router, @@ -3346,7 +3351,7 @@ static void print_error_packet( { while ((buf = gwbuf_consume(buf, GWBUF_LENGTH(buf))) != NULL); } -#endif +#endif /*< SS_DEBUG */ } static int router_get_servercount( @@ -3568,10 +3573,10 @@ static prep_stmt_t* prep_stmt_init( if (pstmt != NULL) { - #if defined(SS_DEBUG) +#if defined(SS_DEBUG) pstmt->pstmt_chk_top = CHK_NUM_PREP_STMT; pstmt->pstmt_chk_tail = CHK_NUM_PREP_STMT; - #endif +#endif pstmt->pstmt_state = PREP_STMT_ALLOC; pstmt->pstmt_type = type;