diff options
author | Richard Knight <q@1bpm.net> | 2022-08-25 18:14:53 +0100 |
---|---|---|
committer | Richard Knight <q@1bpm.net> | 2022-08-25 18:14:53 +0100 |
commit | 9ac4dfb0f0ba5be3f21bd3904c99ba67543b1833 (patch) | |
tree | eda9aabe89979289d61f8ef40f605f18a3223438 /src/opcodes.cpp | |
parent | db5bc3227bf89c0eaf2f2498cf0f1a80cf5eead0 (diff) | |
download | csound-sqldb-9ac4dfb0f0ba5be3f21bd3904c99ba67543b1833.tar.gz csound-sqldb-9ac4dfb0f0ba5be3f21bd3904c99ba67543b1833.tar.bz2 csound-sqldb-9ac4dfb0f0ba5be3f21bd3904c99ba67543b1833.zip |
fixed string and array memory leaks
Diffstat (limited to 'src/opcodes.cpp')
-rw-r--r-- | src/opcodes.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/opcodes.cpp b/src/opcodes.cpp index 34bba02..e82ce33 100644 --- a/src/opcodes.cpp +++ b/src/opcodes.cpp @@ -95,7 +95,7 @@ public: try { switch (queryData->queryType) { case SCALARSTRING: { - std::string resultString = connection->ScalarString(queryData->sql, queryData->row, queryData->col); + std::string resultString = connection->ScalarString(queryData->sql, csound, queryData->row, queryData->col); if (charData != NULL) { csound->free(charData); } @@ -480,6 +480,7 @@ struct dbscalarstr : csnd::Plugin<1, 4> { static constexpr char const *otypes = "S"; static constexpr char const *itypes = "iSoo"; ConnectionData* connection; + char* resultString; int init() { if (!(connection = getConnection(csound, inargs[0]))) { @@ -489,9 +490,12 @@ struct dbscalarstr : csnd::Plugin<1, 4> { STRINGDAT &result = outargs.str_data(0); LOCK(connection); try { - std::string resultString = connection->ScalarString(sql.data, inargs[2], inargs[3]); - result.size = resultString.length() + 1; - result.data = csound->strdup((char*)resultString.c_str()); + if (resultString != NULL) { + csound->free(resultString); + } + resultString = connection->ScalarString(sql.data, csound, inargs[2], inargs[3]); + result.size = strlen(resultString) + 1; + result.data = resultString; } catch (const std::exception &e) { UNLOCK(connection); return csound->init_error(e.what()); @@ -642,9 +646,9 @@ struct dbscalarstr_kb : csnd::Plugin<1, 4> { STRINGDAT &result = outargs.str_data(0); LOCK(connection); try { - std::string resultString = connection->ScalarString(sql.data, inargs[2], inargs[3]); - result.size = resultString.length() + 1; - result.data = csound->strdup((char*) resultString.c_str()); + char* resultString = connection->ScalarString(sql.data, csound, inargs[2], inargs[3]); + result.size = strlen(resultString) + 1; + result.data = resultString; } catch (const std::exception &e) { UNLOCK(connection); return csound->perf_error(e.what(), this); |