Skip to content

Commit 4522e6d

Browse files
committed
Changed Makefile for syb15, revised code to avoid mem leaks on exceptions
1 parent 5d3244f commit 4522e6d

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PROJECT_NAME = db_conn
3838
# could be handy for archiving the generated documentation or if some version
3939
# control system is used.
4040

41-
PROJECT_NUMBER = v0.2.0-alpha
41+
PROJECT_NUMBER = v0.2.1-alpha
4242

4343
# Using the PROJECT_BRIEF tag one can provide an optional one line description
4444
# for a project that appears at the top of each page and should give viewer a

Makefile_syb15.0

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ CC = /opt/gcc/bin/g++
1111
CFLAGS = -std=c++1y -Wall -Wno-unused -Wno-sequence-point -Wno-parentheses -c -ggdb3 -m64 -pthread -DSYB_LP64 -D_REENTRANT
1212

1313
# sybase libraries to include in the build
14-
CTLIB = -lsybct64 # client library
15-
CSLIB = -lsybcs64 # cs library
16-
TCLIB = -lsybtcl64 # transport control layer
17-
COMLIB = -lsybcomn64 # internal shared utility library
18-
INTLLIB = -lsybintl64 # internationalization support library
14+
CTLIB = -lsybct_r64 # client library
15+
CSLIB = -lsybcs_r64 # cs library
16+
TCLIB = -lsybtcl_r64 # transport control layer
17+
COMLIB = -lsybcomn_r64 # internal shared utility library
18+
INTLLIB = -lsybintl_r64 # internationalization support library
19+
BLKLIB = -lsybblk_r64 # bulk copy routines
1920
UNICLIB = -lsybunic64 # unicode library
20-
BLKLIB = -lsybblk64 # bulk copy routines
2121
SYSLIBS = -Wl,-Bdynamic -ldl -lpthread -lnsl -lm
2222
LIBS = -Bstatic $(LIBPATH) $(CTLIB) $(CSLIB) $(TCLIB) $(COMLIB) $(INTLLIB) $(UNICLIB) $(SYSLIBS)
2323

sqlite_driver.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -807,18 +807,15 @@ class statement : public dbi::istatement
807807
cancel();
808808
command = cmd;
809809
command.erase(std::find_if(command.rbegin(), command.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), command.end());
810-
size_t plen = 0U;
811-
std::vector<sqlite3_stmt*> stmts;
812-
sqlite3_stmt* stmt;
810+
size_t plen = 0;
813811
while (command.length() > 0 && plen != command.length())
814812
{
815813
command.erase(command.begin(), std::find_if(command.begin(), command.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
816-
prepare(command, &stmt);
817-
stmts.push_back(stmt);
814+
sqlite_stmts.push_back(nullptr);
815+
prepare(command, &sqlite_stmts[sqlite_stmts.size() - 1]);
818816
plen = command.length();
819817
command = tail;
820818
}
821-
sqlite_stmts = stmts;
822819
return fetch();
823820
}
824821

@@ -1043,7 +1040,7 @@ class statement : public dbi::istatement
10431040
std::string command;
10441041
result_set rs;
10451042
struct tm stm;
1046-
};
1043+
}; // statement
10471044

10481045

10491046
dbi::istatement* connection::get_statement(dbi::iconnection& iconn)

sybase_driver.hpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace vgi { namespace dbconn { namespace dbd { namespace sybase {
3333
static auto TRUE = CS_TRUE;
3434
static auto FALSE = CS_FALSE;
3535

36+
using Locale = CS_LOCALE;
3637
using Context = CS_CONTEXT;
3738
using Connection = CS_CONNECTION;
3839
using ServerMessage = CS_SERVERMSG;
@@ -985,6 +986,8 @@ class driver : public idriver
985986
public:
986987
~driver()
987988
{
989+
if (cslocale != nullptr && cscontext != nullptr)
990+
cs_loc_drop(cscontext, cslocale);
988991
destroy(cscontext);
989992
}
990993

@@ -1210,6 +1213,7 @@ class driver : public idriver
12101213

12111214
void allocate(Context*& cs_context, CS_INT version)
12121215
{
1216+
destroy(cs_context);
12131217
if (CS_SUCCEED != cs_ctx_alloc(version, &cs_context))
12141218
throw std::runtime_error(std::string(__FUNCTION__).append(": Failed to allocate context struct"));
12151219
if (CS_SUCCEED != ct_init(cs_context, version))
@@ -1221,12 +1225,13 @@ class driver : public idriver
12211225

12221226
void destroy(Context*& cs_context)
12231227
{
1224-
if (cslocale != nullptr)
1225-
cs_loc_drop(cscontext, cslocale);
1226-
if (CS_SUCCEED != ct_exit(cs_context, CS_UNUSED))
1227-
ct_exit(cs_context, CS_FORCE_EXIT);
1228-
cs_ctx_drop(cs_context);
1229-
cs_context = nullptr;
1228+
if (cs_context != nullptr)
1229+
{
1230+
if (CS_SUCCEED != ct_exit(cs_context, CS_UNUSED))
1231+
ct_exit(cs_context, CS_FORCE_EXIT);
1232+
cs_ctx_drop(cs_context);
1233+
cs_context = nullptr;
1234+
}
12301235
}
12311236

12321237
CS_INT version()
@@ -1275,10 +1280,10 @@ class driver : public idriver
12751280
#endif
12761281
}
12771282
}
1278-
destroy(cs_context);
12791283
}
12801284
catch (...)
12811285
{ }
1286+
destroy(cs_context);
12821287
return version;
12831288
}
12841289

@@ -1294,7 +1299,7 @@ class driver : public idriver
12941299
"CS_SV_FATAL"
12951300
}};
12961301

1297-
CS_LOCALE* cslocale = nullptr;
1302+
Locale* cslocale = nullptr;
12981303
Context* cscontext = nullptr;
12991304
CS_INT dbg_flag = 0;
13001305
std::string protofile;

0 commit comments

Comments
 (0)