summaryrefslogtreecommitdiff
path: root/libmysqlpp/my-command.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2020-12-12 17:20:40 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2020-12-12 17:20:40 +0000
commit936f41ec0ce1736e74b2fda2c65249956498c777 (patch)
tree0ef446d3d43521417c3bfb57804256fc5d6c22ab /libmysqlpp/my-command.cpp
parentModern jam lto (diff)
downloadlibdbpp-mysql-936f41ec0ce1736e74b2fda2c65249956498c777.tar.bz2
libdbpp-mysql-936f41ec0ce1736e74b2fda2c65249956498c777.tar.xz
libdbpp-mysql-936f41ec0ce1736e74b2fda2c65249956498c777.zip
Smart pointer stmt to fix leak
Diffstat (limited to 'libmysqlpp/my-command.cpp')
-rw-r--r--libmysqlpp/my-command.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/libmysqlpp/my-command.cpp b/libmysqlpp/my-command.cpp
index 539fbf6..7e7275a 100644
--- a/libmysqlpp/my-command.cpp
+++ b/libmysqlpp/my-command.cpp
@@ -5,15 +5,15 @@
#include <cstring>
MySQL::Command::Command(const Connection * conn, const std::string & sql) :
- DB::Command(sql), c(conn), stmt(mysql_stmt_init(&conn->conn)), paramsNeedBinding(false)
+ DB::Command(sql), c(conn), stmt(mysql_stmt_init(&conn->conn), &mysql_stmt_close), paramsNeedBinding(false)
{
if (!stmt) {
throw Error(&conn->conn);
}
- if (mysql_stmt_prepare(stmt, sql.c_str(), sql.length())) {
- throw Error(stmt);
+ if (mysql_stmt_prepare(stmt.get(), sql.c_str(), sql.length())) {
+ throw Error(stmt.get());
}
- binds.resize(mysql_stmt_param_count(stmt));
+ binds.resize(mysql_stmt_param_count(stmt.get()));
if (binds.size()) {
paramsNeedBinding = true;
for (auto & b : binds) {
@@ -29,7 +29,6 @@ MySQL::Command::~Command()
// NOLINTNEXTLINE(hicpp-no-malloc)
free(b.buffer);
}
- mysql_stmt_close(stmt);
}
void *
@@ -160,8 +159,8 @@ void
MySQL::Command::bindParams()
{
if (paramsNeedBinding) {
- if (mysql_stmt_bind_param(stmt, &binds.front())) {
- throw Error(stmt);
+ if (mysql_stmt_bind_param(stmt.get(), &binds.front())) {
+ throw Error(stmt.get());
}
}
}