From 9ac4dfb0f0ba5be3f21bd3904c99ba67543b1833 Mon Sep 17 00:00:00 2001 From: Richard Knight Date: Thu, 25 Aug 2022 18:14:53 +0100 Subject: fixed string and array memory leaks --- include/connection.h | 6 +++--- include/logindata.h | 4 ++-- include/mysql.h | 6 +++--- include/postgresql.h | 6 +++--- include/sqlite.h | 6 +++--- include/tools.h | 30 ++++++++++++++++++++++++++++++ 6 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 include/tools.h (limited to 'include') diff --git a/include/connection.h b/include/connection.h index e67ea27..cf3fb2e 100644 --- a/include/connection.h +++ b/include/connection.h @@ -19,8 +19,8 @@ */ -#ifndef CONNECTION_H -#define CONNECTION_H +#ifndef CSSQLDB_CONNECTION_H +#define CSSQLDB_CONNECTION_H #include #include "logindata.h" @@ -68,7 +68,7 @@ struct ConnectionData { void Close(csnd::Csound* csound); void Exec(char* sql); MYFLT Scalar(char* sql, int row, int col); - char* ScalarString(char* sql, int row=0, int col=0); + char* ScalarString(char* sql, csnd::Csound* csound, int row=0, int col=0); void ArrayQuery(char* sql, csnd::Csound* csound, ARRAYDAT* array); void ArrayQueryString(char* sql, csnd::Csound* csound, ARRAYDAT* array); }; diff --git a/include/logindata.h b/include/logindata.h index 8a62e6b..be8e79a 100644 --- a/include/logindata.h +++ b/include/logindata.h @@ -19,8 +19,8 @@ */ -#ifndef LOGINDATA_H -#define LOGINDATA_H +#ifndef CSSQLDB_LOGINDATA_H +#define CSSQLDB_LOGINDATA_H struct LoginData { int dbType; diff --git a/include/mysql.h b/include/mysql.h index 1abc6e3..950e9d3 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -19,8 +19,8 @@ */ -#ifndef MYSQL_H -#define MYSQL_H +#ifndef CSSQLDB_MYSQL_H +#define CSSQLDB_MYSQL_H #include #include @@ -37,7 +37,7 @@ struct MySQLConnection { void Exec(char* sql); mysql::ResultSet* Query(char *sql); MYFLT Scalar(char* sql, int row, int col); - char* ScalarString(char* sql, int row, int col); + char* ScalarString(char* sql, csnd::Csound* csound, int row, int col); void ToArray(mysql::ResultSet* result, csnd::Csound* csound, ARRAYDAT* array, bool asString); void ArrayQuery(char* sql, csnd::Csound* csound, ARRAYDAT* array); void ArrayQueryString(char* sql, csnd::Csound* csound, ARRAYDAT* array); diff --git a/include/postgresql.h b/include/postgresql.h index 5209057..eaf01c8 100644 --- a/include/postgresql.h +++ b/include/postgresql.h @@ -19,8 +19,8 @@ */ -#ifndef POSTGRESQL_H -#define POSTGRESQL_H +#ifndef CSSQLDB_POSTGRESQL_H +#define CSSQLDB_POSTGRESQL_H #include #include "libpq-fe.h" @@ -33,7 +33,7 @@ struct PostgresConnection { void Exec(char* sql); PGresult* Query(char *sql); MYFLT Scalar(char* sql, int row, int col); - char* ScalarString(char* sql, int row, int col); + char* ScalarString(char* sql, csnd::Csound* csound, int row, int col); void ToArray(PGresult* result, csnd::Csound* csound, ARRAYDAT* array, bool asString); void ArrayQuery(char* sql, csnd::Csound* csound, ARRAYDAT* array); void ArrayQueryString(char* sql, csnd::Csound* csound, ARRAYDAT* array); diff --git a/include/sqlite.h b/include/sqlite.h index 4e2b0c3..c42eb57 100644 --- a/include/sqlite.h +++ b/include/sqlite.h @@ -19,8 +19,8 @@ */ -#ifndef XSQLITE3_H -#define XSQLITE3_H +#ifndef CSSQLDB_SQLITE3_H +#define CSSQLDB_SQLITE3_H #include #include @@ -33,7 +33,7 @@ struct SqliteConnection { void Exec(char* sql); sqlite3_stmt* Query(char *sql); MYFLT Scalar(char* sql, int row, int col); - char* ScalarString(char* sql, int row, int col); + char* ScalarString(char* sql, csnd::Csound* csound, int row, int col); int RowCount(sqlite3_stmt* stmt); void ToArray(sqlite3_stmt* result, csnd::Csound* csound, ARRAYDAT* array, bool asString); void ArrayQuery(char* sql, csnd::Csound* csound, ARRAYDAT* array); diff --git a/include/tools.h b/include/tools.h new file mode 100644 index 0000000..54a0363 --- /dev/null +++ b/include/tools.h @@ -0,0 +1,30 @@ +/* + tools.h + Copyright (C) 2022 Richard Knight + + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ + +#ifndef CSSQLDB_TOOLS_H +#define CSSQLDB_TOOLS_H + +#include + +STRINGDAT* arrayInit(csnd::Csound* csound, ARRAYDAT* array, int rows, int cols); +void insertArrayStringItem(csnd::Csound* csound, STRINGDAT* strings, int index, char* item); + +#endif /* TOOLS_H */ -- cgit v1.2.3