sourcemod/extensions/mysql/extension.cpp
Asher Baker b5de3eb588
Speculative fix for MySQL crashes (#1135)
https://crash.limetech.org/stats/dbi.mysql.ext.%25/my_real_read
https://crash.limetech.org/stats/dbi.mysql.ext.%25/net_real_write

Both of these are caused by the VIO ptr ending up as null in the middle of reading/writing to a connection - I can't find any indication of a fix for this made to MySQL, so don't think it is a bug fix we're missing, but there are some musings around the internet that it could be caused by improper thread-safety initialisation.

`my_init` (what we had here) is called internally by `mysql_library_init` but I think would have still led to an automatic `mysql_library_init` call the first time `mysql_init` was called (which we can do on a thread in case of threaded connections), which is exactly the thread-safety issue called out by the MySQL docs, so hopefully doing things properly here will help.
2019-12-15 15:01:15 +00:00

75 lines
2.3 KiB
C++

/**
* vim: set ts=4 :
* =============================================================================
* SourceMod MySQL Extension
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include <sourcemod_version.h>
#include "extension.h"
#include "mysql/MyDriver.h"
#include <assert.h>
#include <stdlib.h>
/**
* @file extension.cpp
* @brief Implement extension code here.
*/
DBI_MySQL g_MySqlDBI; /**< Global singleton for extension's main interface */
SMEXT_LINK(&g_MySqlDBI);
bool DBI_MySQL::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
if (mysql_library_init(0, NULL, NULL) != 0) {
smutils->Format(error, maxlength, "Could not initialize MySQL client library");
return false;
}
dbi->AddDriver(&g_MyDriver);
return true;
}
void DBI_MySQL::SDK_OnUnload()
{
dbi->RemoveDriver(&g_MyDriver);
mysql_library_end();
}
const char *DBI_MySQL::GetExtensionVerString()
{
return SOURCEMOD_VERSION;
}
const char *DBI_MySQL::GetExtensionDateString()
{
return SOURCEMOD_BUILD_TIME;
}