Skip to content

[PostgreSQL] delete DBStatement cause server crash #1946

@ProjectSky

Description

@ProjectSky

Help us help you

  • I have checked that my issue doesn't exist yet.
  • I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
  • I can always reproduce the issue with the provided description below.

Environment

  • Operating System version:
  • Game/AppID (with version if applicable):
  • Current SourceMod version:
  • Current SourceMod snapshot:
  • Current Metamod: Source snapshot:

Description

I tested similar code in MySQL and it doesn't crash, so this only happens with pgsql

Problematic Code (or Steps to Reproduce)

...
char sClientIP[16], sError[256];

GetClientIP(client, sClientIP, sizeof(sClientIP));

DBStatement hInsertQuery;

FormatEx(g_sQuery, sizeof(g_sQuery), "INSERT INTO test_table (steamid, name, ip, firstjoin) VALUES ($1, $2, $3, $4) ON CONFLICT (steamid) DO NOTHING");

if ((hInsertQuery = SQL_PrepareQuery(g_hDataBase, g_sQuery, sError, sizeof(sError))) == null)
{
	delete hInsertQuery;
	LogError("Failed %s", sError);
	return;
}

hInsertQuery.BindString(0, players[client].steamid, false);
hInsertQuery.BindString(1, players[client].name, false);
hInsertQuery.BindString(2, sClientIP, false);
hInsertQuery.BindInt(3, GetTime());

if (SQL_Execute(hInsertQuery))
{
	PrintToServer("InsertQuery Success!");
}

delete hInsertQuery; // server crash
...

Logs

server console

InsertQuery Success!
free(): invalid pointer
**server crash**

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions