From a3c90e1fc6dc6972c258a8d5671658dc347b995d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sat, 23 Jul 2016 15:46:57 +0000 Subject: [PATCH] Further improvement on Monitor Fixed a memory leak Fixed a double mysql_close() --- lib/MySQL_Monitor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index 23a7c3240..2c07532a6 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -60,6 +60,7 @@ class ConsumerThread : public Thread { // printf("thread %d, loop %d - got one item\n", thrn, i); item->routine((void *)item->mmsd); //routine((void *)mmsd); + delete item->mmsd; delete item; } return NULL; @@ -397,6 +398,7 @@ void * monitor_connect_thread(void *arg) { sqlite3_finalize(statement); mysql_close(mmsd->mysql); + mmsd->mysql=NULL; delete mysql_thr; return NULL; } @@ -465,6 +467,7 @@ __exit_monitor_ping_thread: __fast_exit_monitor_ping_thread: if (mmsd->mysql) { mysql_close(mmsd->mysql); // if we reached here we didn't put the connection back + mmsd->mysql=NULL; } delete mysql_thr; return NULL; @@ -583,7 +586,7 @@ __exit_monitor_read_only_thread: fields = mysql_fetch_fields(mmsd->result); for(k = 0; k < num_fields; k++) { //if (strcmp("VARIABLE_NAME", fields[k].name)==0) { - if (strcmp("Value", fields[k].name)==0) { + if (strcmp((char *)"Value", (char *)fields[k].name)==0) { j=k; } } @@ -623,6 +626,7 @@ __exit_monitor_read_only_thread: __fast_exit_monitor_read_only_thread: if (mmsd->mysql) { mysql_close(mmsd->mysql); // if we reached here we didn't put the connection back + mmsd->mysql=NULL; } delete mysql_thr; return NULL; @@ -750,6 +754,7 @@ __exit_monitor_replication_lag_thread: __fast_exit_monitor_replication_lag_thread: if (mmsd->mysql) { mysql_close(mmsd->mysql); // if we reached here we didn't put the connection back + mmsd->mysql=NULL; } delete mysql_thr; return NULL;