From 196fd0a474e4f97a78dfc39850ff57a887eda5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 7 Dec 2016 17:43:28 +0000 Subject: [PATCH] Memory leak on error during STMT_EXECUTE #796 --- lib/MySQL_Session.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index dfe05ad4f..772ab5558 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -159,6 +159,15 @@ void Query_Info::end() { //__sync_fetch_and_sub(&stmt_info->ref_count,1); // decrease reference count stmt_info=NULL; } + if (stmt_meta) { // fix bug #796: memory is not freed in case of error during STMT_EXECUTE + if (stmt_meta->pkt) { + uint32_t stmt_global_id=0; + memcpy(&stmt_global_id,(char *)(stmt_meta->pkt)+5,sizeof(uint32_t)); + sess->SLDH->reset(stmt_global_id); + free(stmt_meta->pkt); + stmt_meta->pkt=NULL; + } + } } void Query_Info::init(unsigned char *_p, int len, bool mysql_header) {