diff --git a/include/query_processor.h b/include/query_processor.h index 1b90a024a..8c5988e9a 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -125,6 +125,12 @@ class Query_Processor_Output { l_free(sizeof(Query_Processor_Output),ptr); } Query_Processor_Output() { + init(); + } + ~Query_Processor_Output() { + destroy(); + } + void init() { ptr=NULL; size=0; destination_hostgroup=-1; @@ -139,9 +145,10 @@ class Query_Processor_Output { new_query=NULL; error_msg=NULL; } - ~Query_Processor_Output() { + void destroy() { if (error_msg) { free(error_msg); + error_msg=NULL; } } }; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index bd355d0bf..b69c6df9d 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -192,7 +192,7 @@ void MySQL_Session::operator delete(void *ptr) { MySQL_Session::MySQL_Session() { thread_session_id=0; pause_until=0; - qpo=NULL; + qpo=new Query_Processor_Output(); // Session_STMT_Manager=NULL; start_time=0; command_counters=new StatCounters(15,10,false); @@ -255,6 +255,8 @@ MySQL_Session::~MySQL_Session() { if (admin==false && connections_handler==false && mirror==false) { __sync_fetch_and_sub(&MyHGM->status.client_connections,1); } + assert(qpo); + delete qpo; // if (Session_STMT_Manager) { // delete Session_STMT_Manager; // } @@ -2826,10 +2828,11 @@ void MySQL_Session::RequestEnd(MySQL_Data_Stream *myds) { } // clean qpo - if (qpo) { - GloQPro->delete_QP_out(qpo); - qpo=NULL; - } + //if (qpo) { + // GloQPro->delete_QP_out(qpo); + // qpo=NULL; + //} + GloQPro->delete_QP_out(qpo); // if there is an associated myds, clean its status if (myds) { // if there is a mysql connection, clean its status diff --git a/lib/Query_Processor.cpp b/lib/Query_Processor.cpp index 6f40f3851..fd51d8907 100644 --- a/lib/Query_Processor.cpp +++ b/lib/Query_Processor.cpp @@ -602,8 +602,11 @@ SQLite3_result * Query_Processor::get_query_digests_reset() { Query_Processor_Output * Query_Processor::process_mysql_query(MySQL_Session *sess, void *ptr, unsigned int size, Query_Info *qi) { - Query_Processor_Output *ret=NULL; - ret=new Query_Processor_Output(); + // to avoid unnecssary deallocation/allocation, we initialize qpo witout new allocation + //Query_Processor_Output *ret=NULL; + //ret=new Query_Processor_Output(); + Query_Processor_Output *ret=sess->qpo; + ret->init(); SQP_par_t *qp=NULL; if (qi) { qp=(SQP_par_t *)&qi->QueryParserArgs; @@ -829,7 +832,8 @@ __exit_process_mysql_query: void Query_Processor::delete_QP_out(Query_Processor_Output *o) { //l_free(sizeof(QP_out_t),o); if (o) { - delete o; + //delete o; // do not deallocate, but "destroy" it + o->destroy(); } };