sourcemod
sourcemod copied to clipboard
[PostgreSQL] delete DBStatement cause server crash
Help us help you
- [x] I have checked that my issue doesn't exist yet.
- [x] I have tried my absolute best to reduce the problem-space and have provided the absolute smallest test-case possible.
- [x] 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:
- [x] I have updated SourceMod to the latest version and it still happens.
- [x] I have updated SourceMod to the latest snapshot and it still happens.
- [x] I have updated SourceMM to the latest snapshot and it still happens.
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**
This happens to me when executing modern STL code with monster (run-time) LD-RedHat optimizations after built on GNU Binutils 2.26.1 (old SteamRT/Valve style for Source Engine binaries).
https://github.com/search?q=repo%3Aalliedmodders%2Fsourcemod+lang%3AC%2B%2B+istringstream&type=code
My backtrace.
Sorry for the screenshot, this is an archived/old local issue
In my situation, at the moment, I recommend using a really stable branch (no 1.11+) — https://www.sourcemod.net/downloads.php?branch=1.10-dev with a modern hl2sdk rebuilt, if your game is updatable
Throttle stats link: https://crash.limetech.org/stats/dbi.pgsql.ext.%25/PgStatement::Destroy%25?frame=any
My backtrace.
I don't think this crash is related.
This is a bad idea, but can try using https://github.com/alliedmodders/sourcemod/pull/1689/files (VMS) for more stable behavior with a free object by bug pointer in range of page poll. On my part, there will be an posible (I can do it in my free time with #1689 ) to debug where the object with bug pointer value was damaged in run-time (similar to GDB debugging, you can do it yourself without waiting for me).