Skip to content

Commit

Permalink
Fix of memory leak introduced earlier
Browse files Browse the repository at this point in the history
In case of error in SQLTables query execution, and exception would be
thrown, and that would bybass allocated memory freeing.

Removed in static varible initialization reference to static variable
from other translation unit. That crashed tests on centos7

Adding automatically dependencies to the Deb package.
  • Loading branch information
lawrinn committed Nov 27, 2023
1 parent ea408ce commit 3e4d81e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Expand Up @@ -228,7 +228,7 @@ IF(WITH_SIGNCODE)
MARK_AS_ADVANCED(SIGN_OPTIONS)
ENDIF()

#Debug log is controlled by conenction option solely
#Debug log is controlled by connection option solely
ADD_DEFINITIONS(-DMAODBC_DEBUG)

IF(WIN32)
Expand Down Expand Up @@ -423,6 +423,9 @@ ELSE()

ENDIF()
ELSE()
#SET(CPACK_DEBIAN_ODBCLibs_PACKAGE_SHLIBDEPS ON)
#SET(CPACK_DEBIAN_PACKAGE_DEPENDS "unixodbc-dev")
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_BINARY_DIR}/packaging/linux/postinstall")
ENDIF()

Expand Down
1 change: 1 addition & 0 deletions driver/class/Protocol.cpp
Expand Up @@ -37,6 +37,7 @@

namespace mariadb
{
const int64_t Protocol::MAX_PACKET_LENGTH= 0x00ffffff + 4;
static const char OptionSelected= 1, OptionNotSelected= 0;
static const unsigned int uintOptionSelected= 1, uintOptionNotSelected= 0;
static const SQLString MARIADB_RPL_HACK_PREFIX("5.5.5-");
Expand Down
2 changes: 1 addition & 1 deletion driver/class/Protocol.h
Expand Up @@ -111,7 +111,7 @@ class Protocol
void unsyncedReset();

public:
static const int64_t MAX_PACKET_LENGTH= 0x00ffffff + 4;
static const int64_t MAX_PACKET_LENGTH;
static bool checkRemainingSize(int64_t newQueryLen);

~Protocol() {}
Expand Down
12 changes: 10 additions & 2 deletions driver/ma_catalog.cpp
Expand Up @@ -373,7 +373,6 @@ SQLRETURN MADB_StmtTables(MADB_Stmt *Stmt, char *CatalogName, SQLSMALLINT Catalo
return MADB_SetError(&Stmt->Error, MADB_ERR_HY001, NULL, 0);
}


if (CatalogName != NULL)
{
MADB_DYNAPPENDCONST(&StmtStr, " AND TABLE_SCHEMA");
Expand Down Expand Up @@ -414,7 +413,16 @@ SQLRETURN MADB_StmtTables(MADB_Stmt *Stmt, char *CatalogName, SQLSMALLINT Catalo
}
MDBUG_C_PRINT(Stmt->Connection, "SQL Statement: %s", StmtStr.str);

ret= Stmt->Methods->ExecDirect(Stmt, StmtStr.str, SQL_NTS);
try
{
ret= Stmt->Methods->ExecDirect(Stmt, StmtStr.str, SQL_NTS);
}
catch (SQLException &e)
{
// We need to intercept exception here to be able to free the memory.
// TODO: change it so there is no need to intercept - i.e. remove DynStr and substitute it w/ smth c++ish
ret= MADB_FromException(Stmt->Error, e);
}

MADB_DynstrFree(&StmtStr);

Expand Down
2 changes: 1 addition & 1 deletion driver/ma_info.cpp
Expand Up @@ -27,7 +27,7 @@
#define BV(_STRCONST) mariadb::bytes_view(_STRCONST, sizeof(_STRCONST))
#define XBV(_STRCONST) BV(#_STRCONST)

static mariadb::bytes_view zero("0", 2), one("1", 2), three("3", 2), Null, ten("10", 3), empty(emptyStr),
static mariadb::bytes_view zero("0", 2), one("1", 2), three("3", 2), Null, ten("10", 3), empty("",1),
sqlwchar("-8", 3), sqlwvarchar("-9", 3), sqlwlongvarchar("-10", 4), sqlbit("-7", 3), sqltinyint("-6", 3),
sqlbigint("-5", 3), sqllongvarbinary("-4", 3), sqlvarbinary("-3", 3), sqlbinary("-2", 3), sqllongvarchar("-1", 3); // They defined as (-8) etc, and that's not parsed well as int

Expand Down

0 comments on commit 3e4d81e

Please sign in to comment.