Open gesior opened 1 week ago
I fixed this by replacing:
bool Database::executeQuery(const std::string& query)
{
std::lock_guard<std::recursive_mutex> lockGuard(databaseLock);
return ::executeQuery(handle, query, retryQueries);
}
with:
bool Database::executeQuery(const std::string& query)
{
std::lock_guard<std::recursive_mutex> lockGuard(databaseLock);
auto success = ::executeQuery(handle, query, retryQueries);
// we should call that every time as someone would call executeQuery('SELECT...')
// as it is described in MySQL manual: "it doesn't hurt" :P
tfs::detail::MysqlResult_ptr res{mysql_store_result(handle.get())};
return success;
}
Can anyone experienced with shared pointers check, if there is no memory leak?
From my understanding of shared pointers:
It will convert result (if exists) into shared pointer and this shared pointer will be deleted at end of function. Deletion of MysqlResult_ptr
will call mysql_free_result
( https://github.com/otland/forgottenserver/blob/1.6/src/database.h#L14-L21 ), so it should not leak any memory.
By submitting this bug issue, you agree to the following.
Does this bug crash tfs?
no
Server Version
1.7 (Master), 1.6 (Release)
Operation System
all (listed below)
OS Description
No response
Bug description
After running
SELECT
query withDatabase::executeQuery
(Lua:db.query
) server is not able to execute SQL queries anymore.Ex. this C++ code executes
executeQuery
which may return some results (if anything is optimized):if (db.executeQuery(fmt::format("OPTIMIZE TABLE
{:s}", tableName))) {
Possible Pull Requests which are to blame
4626
Steps to reproduce
db.query
(you should rundb.storeQuery
) with SQL query that returns some result from MySQLCommands out of sync; you can't run this command now
Code to reproduce the issue:
Actual Behavior
Running
Database::executeQuery
withSELECT
blocks all next SQL queries.Expected Behavior
Small bug in C++/Lua should not block all next SQL queries.
Backtrace
No response