From 89c05d8c9fd941e4f89f60bf9c1f1c1f26886a62 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 0990d3166..c0afaa323 100644 --- a/gb.db.odbc/src/main.c +++ b/gb.db.odbc/src/main.c @@ -688,8 +688,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. */ @@ -697,8 +699,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())