From 4522e6d6f91f40acd6d1d376d5d6b8c945ea39f8 Mon Sep 17 00:00:00 2001 From: vimsh Date: Fri, 24 Mar 2017 20:35:36 -0400 Subject: [PATCH] Changed Makefile for syb15, revised code to avoid mem leaks on exceptions --- Doxyfile | 2 +- Makefile_syb15.0 | 12 ++++++------ sqlite_driver.hpp | 11 ++++------- sybase_driver.hpp | 21 +++++++++++++-------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Doxyfile b/Doxyfile index 2523485..f0662b0 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = db_conn # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = v0.2.0-alpha +PROJECT_NUMBER = v0.2.1-alpha # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/Makefile_syb15.0 b/Makefile_syb15.0 index bb83a28..3875d04 100644 --- a/Makefile_syb15.0 +++ b/Makefile_syb15.0 @@ -11,13 +11,13 @@ CC = /opt/gcc/bin/g++ CFLAGS = -std=c++1y -Wall -Wno-unused -Wno-sequence-point -Wno-parentheses -c -ggdb3 -m64 -pthread -DSYB_LP64 -D_REENTRANT # sybase libraries to include in the build -CTLIB = -lsybct64 # client library -CSLIB = -lsybcs64 # cs library -TCLIB = -lsybtcl64 # transport control layer -COMLIB = -lsybcomn64 # internal shared utility library -INTLLIB = -lsybintl64 # internationalization support library +CTLIB = -lsybct_r64 # client library +CSLIB = -lsybcs_r64 # cs library +TCLIB = -lsybtcl_r64 # transport control layer +COMLIB = -lsybcomn_r64 # internal shared utility library +INTLLIB = -lsybintl_r64 # internationalization support library +BLKLIB = -lsybblk_r64 # bulk copy routines UNICLIB = -lsybunic64 # unicode library -BLKLIB = -lsybblk64 # bulk copy routines SYSLIBS = -Wl,-Bdynamic -ldl -lpthread -lnsl -lm LIBS = -Bstatic $(LIBPATH) $(CTLIB) $(CSLIB) $(TCLIB) $(COMLIB) $(INTLLIB) $(UNICLIB) $(SYSLIBS) diff --git a/sqlite_driver.hpp b/sqlite_driver.hpp index 37ff150..fbe63c2 100644 --- a/sqlite_driver.hpp +++ b/sqlite_driver.hpp @@ -807,18 +807,15 @@ class statement : public dbi::istatement cancel(); command = cmd; command.erase(std::find_if(command.rbegin(), command.rend(), std::not1(std::ptr_fun(std::isspace))).base(), command.end()); - size_t plen = 0U; - std::vector stmts; - sqlite3_stmt* stmt; + size_t plen = 0; while (command.length() > 0 && plen != command.length()) { command.erase(command.begin(), std::find_if(command.begin(), command.end(), std::not1(std::ptr_fun(std::isspace)))); - prepare(command, &stmt); - stmts.push_back(stmt); + sqlite_stmts.push_back(nullptr); + prepare(command, &sqlite_stmts[sqlite_stmts.size() - 1]); plen = command.length(); command = tail; } - sqlite_stmts = stmts; return fetch(); } @@ -1043,7 +1040,7 @@ class statement : public dbi::istatement std::string command; result_set rs; struct tm stm; -}; +}; // statement dbi::istatement* connection::get_statement(dbi::iconnection& iconn) diff --git a/sybase_driver.hpp b/sybase_driver.hpp index 1841c10..b47a554 100644 --- a/sybase_driver.hpp +++ b/sybase_driver.hpp @@ -33,6 +33,7 @@ namespace vgi { namespace dbconn { namespace dbd { namespace sybase { static auto TRUE = CS_TRUE; static auto FALSE = CS_FALSE; +using Locale = CS_LOCALE; using Context = CS_CONTEXT; using Connection = CS_CONNECTION; using ServerMessage = CS_SERVERMSG; @@ -985,6 +986,8 @@ class driver : public idriver public: ~driver() { + if (cslocale != nullptr && cscontext != nullptr) + cs_loc_drop(cscontext, cslocale); destroy(cscontext); } @@ -1210,6 +1213,7 @@ class driver : public idriver void allocate(Context*& cs_context, CS_INT version) { + destroy(cs_context); if (CS_SUCCEED != cs_ctx_alloc(version, &cs_context)) throw std::runtime_error(std::string(__FUNCTION__).append(": Failed to allocate context struct")); if (CS_SUCCEED != ct_init(cs_context, version)) @@ -1221,12 +1225,13 @@ class driver : public idriver void destroy(Context*& cs_context) { - if (cslocale != nullptr) - cs_loc_drop(cscontext, cslocale); - if (CS_SUCCEED != ct_exit(cs_context, CS_UNUSED)) - ct_exit(cs_context, CS_FORCE_EXIT); - cs_ctx_drop(cs_context); - cs_context = nullptr; + if (cs_context != nullptr) + { + if (CS_SUCCEED != ct_exit(cs_context, CS_UNUSED)) + ct_exit(cs_context, CS_FORCE_EXIT); + cs_ctx_drop(cs_context); + cs_context = nullptr; + } } CS_INT version() @@ -1275,10 +1280,10 @@ class driver : public idriver #endif } } - destroy(cs_context); } catch (...) { } + destroy(cs_context); return version; } @@ -1294,7 +1299,7 @@ class driver : public idriver "CS_SV_FATAL" }}; - CS_LOCALE* cslocale = nullptr; + Locale* cslocale = nullptr; Context* cscontext = nullptr; CS_INT dbg_flag = 0; std::string protofile;