From 3c84b78d13b2226a11d7510dab8f4db197ec86ca Mon Sep 17 00:00:00 2001 From: gambas Date: Mon, 16 Jul 2018 17:56:37 +0200 Subject: [PATCH] Fix a memory leak when connecting to a database. [GB.DB.ODBC] * BUG: Fix a memory leak when connecting to a database. --- gb.db.odbc/src/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gb.db.odbc/src/main.c b/gb.db.odbc/src/main.c index e2d9689b9..dcfd3cb41 100644 --- a/gb.db.odbc/src/main.c +++ b/gb.db.odbc/src/main.c @@ -686,8 +686,10 @@ void GetConnectedDBName(DB_DESC *desc, ODBC_CONN *odbc) if (SQL_SUCCEEDED(retcode)) { - dbName = malloc(sizeof(SQLTCHAR) * charsNeeded++); - dbName[sizeof(SQLTCHAR) * charsNeeded++] = 0; + charsNeeded++; + + dbName = malloc(sizeof(SQLTCHAR) * charsNeeded); + /*zxMarce: We call the function again, this time specifying a hopefully big enough buffer for storing the catalog name. */ @@ -695,8 +697,11 @@ void GetConnectedDBName(DB_DESC *desc, ODBC_CONN *odbc) dbName, charsNeeded, &charsNeeded ); + dbName[sizeof(SQLTCHAR) * charsNeeded] = 0; + GB.FreeString(&desc->name); desc->name = GB.NewZeroString((char *)dbName); + free(dbName); } if (DB.IsDebug())