Fix a memory leak when connecting to a database.

[GB.DB.ODBC]
* BUG: Fix a memory leak when connecting to a database.
This commit is contained in:
gambas 2018-07-16 17:56:37 +02:00
parent 9abaadc360
commit 3c84b78d13

View file

@ -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())