未验证 提交 8b7674f9 编写于 作者: A atoomix 提交者: GitHub

support build with address sanitizer and fix some memory leaks (#86)

* support build with address sanitizer

using cmake options `-DENALBE_ASAN=ON` to enable address sanitizer

* fix some memory leaks detected by asan
上级 d5c676a5
...@@ -55,6 +55,13 @@ SET(CMAKE_CXX_FLAGS ${CMAKE_COMMON_FLAGS}) ...@@ -55,6 +55,13 @@ SET(CMAKE_CXX_FLAGS ${CMAKE_COMMON_FLAGS})
SET(CMAKE_C_FLAGS ${CMAKE_COMMON_FLAGS}) SET(CMAKE_C_FLAGS ${CMAKE_COMMON_FLAGS})
MESSAGE("CMAKE_CXX_FLAGS is " ${CMAKE_CXX_FLAGS}) MESSAGE("CMAKE_CXX_FLAGS is " ${CMAKE_CXX_FLAGS})
OPTION(ENABLE_ASAN OFF "Enable build with address sanitizer")
IF (ENABLE_ASAN)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer -fsanitize=address")
SET(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
ENDIF()
IF (CMAKE_INSTALL_PREFIX) IF (CMAKE_INSTALL_PREFIX)
MESSAGE("CMAKE_INSTALL_PREFIX has been set as " ${CMAKE_INSTALL_PREFIX} ) MESSAGE("CMAKE_INSTALL_PREFIX has been set as " ${CMAKE_INSTALL_PREFIX} )
......
...@@ -215,6 +215,7 @@ private: ...@@ -215,6 +215,7 @@ private:
} }
searcher_.erase(node); searcher_.erase(node);
delete node;
} }
private: private:
......
...@@ -13,7 +13,12 @@ See the Mulan PSL v2 for more details. */ ...@@ -13,7 +13,12 @@ See the Mulan PSL v2 for more details. */
// //
#include "event/sql_event.h" #include "event/sql_event.h"
#include <cstddef>
#include "event/session_event.h" #include "event/session_event.h"
#include "sql/parser/parse_defs.h"
#include "sql/stmt/stmt.h"
SQLStageEvent::SQLStageEvent(SessionEvent *event, const std::string &sql) : session_event_(event), sql_(sql) SQLStageEvent::SQLStageEvent(SessionEvent *event, const std::string &sql) : session_event_(event), sql_(sql)
{} {}
...@@ -26,4 +31,14 @@ SQLStageEvent::~SQLStageEvent() noexcept ...@@ -26,4 +31,14 @@ SQLStageEvent::~SQLStageEvent() noexcept
// session_event_ = nullptr; // session_event_ = nullptr;
// session_event->doneImmediate(); // session_event->doneImmediate();
} }
if (query_ != nullptr) {
query_destroy(query_);
query_ = nullptr;
}
if (stmt_ != nullptr) {
delete stmt_;
stmt_ = nullptr;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册