Skip to content

Commit a55878f

Browse files
committed
Dsn could be leaked if connection re-used after disconnect.
Disabled one check in the test in unicode to reduce noise with valgrind
1 parent 51f21fe commit a55878f

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

driver/ma_connection.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ bool MADB_Dbc::CheckConnection()
141141
SQLRETURN MADB_SQLDisconnect(SQLHDBC ConnectionHandle)
142142
{
143143
SQLRETURN ret= SQL_ERROR;
144-
MADB_Dbc* Connection= (MADB_Dbc*)ConnectionHandle;
145-
MADB_List* Element, * NextElement;
144+
MADB_Dbc *Connection= (MADB_Dbc*)ConnectionHandle;
145+
MADB_List *Element, *NextElement;
146146

147147
MDBUG_C_ENTER(Connection, "SQLDisconnect");
148148
MDBUG_C_DUMP(Connection, ConnectionHandle, 0x);
@@ -161,7 +161,9 @@ SQLRETURN MADB_SQLDisconnect(SQLHDBC ConnectionHandle)
161161
NextElement= Element->next;
162162
MADB_DescFree((MADB_Desc*)Element->data, FALSE);
163163
}
164-
164+
// Even if the handle is re-used - we won't need this Dsn
165+
MADB_DSN_Free(Connection->Dsn);
166+
Connection->Dsn= nullptr;
165167
Connection->mariadb= nullptr;
166168
if (Connection->guard && !Connection->guard->isClosed())
167169
{

driver/ma_dsn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ my_bool MADB_ReadDSN(MADB_Dsn *Dsn, const char *KeyValue, my_bool OverWrite)
407407
{
408408
unsigned int KeyIdx= DsnKeys[i].IsAlias ? DsnKeys[i].DsnOffset : i;
409409

410-
if (SQLGetPrivateProfileString(Dsn->DSNName, DsnKeys[i].DsnKey, "", KeyVal, 1024, "ODBC.INI") > 0)
410+
if (SQLGetPrivateProfileString(Dsn->DSNName, DsnKeys[i].DsnKey, "", KeyVal, sizeof(KeyVal), "ODBC.INI") > 0)
411411
{
412412
if (!MADB_DsnStoreValue(Dsn, KeyIdx, KeyVal, OverWrite))
413413
return FALSE;

test/bulk.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ ODBC_TEST(t_odbc235)
728728
(SQLPOINTER)1, 0));
729729

730730
OK_SIMPLE_STMT(Stmt, "DROP TABLE IF EXISTS t_odbc235");
731+
CHECK_STMT_RC(wStmt, SQLFreeStmt(wStmt, SQL_DROP));
732+
731733
return OK;
732734
}
733735

test/tap.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,11 @@ int run_tests_ex(MA_ODBC_TESTS *tests, BOOL ProvideWConnection)
12281228
/* reset Statement */
12291229
fflush(stdout);
12301230
}
1231-
1231+
if (wConnection)
1232+
{
1233+
SQLDisconnect(wConnection);
1234+
SQLFreeHandle(SQL_HANDLE_DBC, wConnection);
1235+
}
12321236
ODBC_Disconnect(Env,Connection,Stmt);
12331237

12341238
if (failed)

test/unicode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,14 @@ ODBC_TEST(sqlchar)
258258
FAIL_IF(SQLFetch(hstmt1) != SQL_NO_DATA_FOUND, "eof expected");
259259

260260
CHECK_STMT_RC(hstmt1, SQLFreeStmt(hstmt1, SQL_DROP));
261+
// This check creates lots of noise with valgrind from inside unixODBC
262+
#ifndef MEMCHECK_SKIP_TEST
261263
// We probably could do that in driver as well, TODO: but do we really need
262264
if (using_dm())
263265
{
264266
is_num(SQLFreeHandle(SQL_HANDLE_STMT, hstmt1), SQL_INVALID_HANDLE);
265267
}
268+
#endif
266269
CHECK_DBC_RC(hdbc1, SQLDisconnect(hdbc1));
267270
CHECK_DBC_RC(hdbc1, SQLFreeConnect(hdbc1));
268271

0 commit comments

Comments
 (0)