Skip to content

Commit

Permalink
Merge pull request #26 from sapphonie/hotfix-db-leak
Browse files Browse the repository at this point in the history
Hotfix db leak
  • Loading branch information
sapphonie authored Dec 6, 2024
2 parents 08c5391 + d65321d commit e94833d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions addons/sourcemod/scripting/mge.sp
Original file line number Diff line number Diff line change
Expand Up @@ -3787,36 +3787,52 @@ void PrepareSQL() // Opens the connection to the database, and creates the table
{
char error[256];

if (SQL_CheckConfig(g_sDBConfig))
db = SQL_Connect(g_sDBConfig, true, error, sizeof(error));
// initial mysql connect
if (db == null && SQL_CheckConfig(g_sDBConfig))
{
db = SQL_Connect(g_sDBConfig, /* persistent */ true, error, sizeof(error));
}

// failed mysql connect for whatever reason (likely no config in databases.cfg)
if (db == null)
{
LogError("Cant use database config <%s> <Error: %s>, trying SQLite <storage-local>...", g_sDBConfig, error);
db = SQL_Connect("storage-local", true, error, sizeof(error));

if (db == null)
{
SetFailState("Could not connect to database: %s", error);
}
else
LogError("Success, using SQLite <storage-local>", g_sDBConfig, error);
{
LogMessage("Success, using SQLite <storage-local>", g_sDBConfig, error);
}
}

char ident[16];
db.Driver.GetIdentifier(ident, sizeof(ident));

if (StrEqual(ident, "mysql", false))
{
g_bUseSQLite = false;
}
else if (StrEqual(ident, "sqlite", false))
{
g_bUseSQLite = true;
}
else
{
SetFailState("Invalid database.");
}

if (g_bUseSQLite)
{
db.Query(SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS mgemod_stats (rating INTEGER, steamid TEXT, name TEXT, wins INTEGER, losses INTEGER, lastplayed INTEGER, hitblip INTEGER)");
db.Query(SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS mgemod_duels (winner TEXT, loser TEXT, winnerscore INTEGER, loserscore INTEGER, winlimit INTEGER, gametime INTEGER, mapname TEXT, arenaname TEXT) ");
db.Query(SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS mgemod_duels_2v2 (winner TEXT, winner2 TEXT, loser TEXT, loser2 TEXT, winnerscore INTEGER, loserscore INTEGER, winlimit INTEGER, gametime INTEGER, mapname TEXT, arenaname TEXT) ");
} else {
}
else
{
db.Query(SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS mgemod_stats (rating INT(4) NOT NULL, steamid VARCHAR(32) NOT NULL, name VARCHAR(64) NOT NULL, wins INT(4) NOT NULL, losses INT(4) NOT NULL, lastplayed INT(11) NOT NULL, hitblip INT(2) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB ");
db.Query(SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS mgemod_duels (winner VARCHAR(32) NOT NULL, loser VARCHAR(32) NOT NULL, winnerscore INT(4) NOT NULL, loserscore INT(4) NOT NULL, winlimit INT(4) NOT NULL, gametime INT(11) NOT NULL, mapname VARCHAR(64) NOT NULL, arenaname VARCHAR(32) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB ");
db.Query(SQLErrorCheckCallback, "CREATE TABLE IF NOT EXISTS mgemod_duels_2v2 (winner VARCHAR(32) NOT NULL, winner2 VARCHAR(32) NOT NULL, loser VARCHAR(32) NOT NULL, loser2 VARCHAR(32) NOT NULL, winnerscore INT(4) NOT NULL, loserscore INT(4) NOT NULL, winlimit INT(4) NOT NULL, gametime INT(11) NOT NULL, mapname VARCHAR(64) NOT NULL, arenaname VARCHAR(32) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB ");
Expand Down

0 comments on commit e94833d

Please sign in to comment.