small fix

This commit is contained in:
alice
2026-07-28 03:26:12 +02:00
parent eb6341882d
commit 6beabba9e5
+29 -24
View File
@@ -338,6 +338,21 @@ namespace mysql
connection.cleanup(); connection.cleanup();
} }
} }
void free_statement_binds(MYSQL_BIND* binds, const std::size_t bind_count)
{
if (binds == nullptr)
{
return;
}
for (auto i = 0u; i < bind_count; i++)
{
utils::memory::free(binds[i].buffer);
}
utils::memory::free(binds);
}
} }
utils::concurrency::container<sql::connection_config>& get_config() utils::concurrency::container<sql::connection_config>& get_config()
@@ -476,22 +491,7 @@ namespace mysql
gsc::function::add("mysql::prepared_statement", [](const std::string& query, const scripting::variadic_args& values) gsc::function::add("mysql::prepared_statement", [](const std::string& query, const scripting::variadic_args& values)
{ {
MYSQL_BIND* binds = nullptr; MYSQL_BIND* binds = nullptr;
size_t bind_count = 0; auto bind_count = 0u;
const auto free_binds = [=]
{
if (binds == nullptr)
{
return;
}
for (auto i = 0u; i < bind_count; i++)
{
utils::memory::free(binds[i].buffer);
}
utils::memory::free(binds);
};
try try
{ {
@@ -503,16 +503,13 @@ namespace mysql
{ {
binds = bind_statement_args(values, bind_count); binds = bind_statement_args(values, bind_count);
} }
}
catch (const std::exception& e)
{
free_binds();
throw e;
}
return create_mysql_query([=](database_t& db) const auto handle = create_mysql_query([binds, bind_count, query](database_t& db)
{ {
const auto _0 = gsl::finally(free_binds); const auto _0 = gsl::finally([=]
{
free_statement_binds(binds, bind_count);
});
mysql_result_t result{}; mysql_result_t result{};
@@ -532,6 +529,14 @@ namespace mysql
return result; return result;
}); });
return handle;
}
catch (const std::exception& e)
{
free_statement_binds(binds, bind_count);
throw e;
}
}); });
} }
}; };