From b4480be526457da49dbcfeefd0d4071900a86f84 Mon Sep 17 00:00:00 2001 From: peavey Date: Mon, 15 Jan 2007 20:17:06 +0000 Subject: Fix possible segfault if sql query failed. Using a free'd char is probably not a good thing. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6347 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_sqlite3.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/modules/extra') diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index 5fba3880e..9c66c4f11 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -269,8 +269,7 @@ class SQLConn : public classbase SQLConn(InspIRCd* SI, Module* m, const SQLhost& hi) : Instance(SI), mod(m), host(hi) { - int result; - if ((result = OpenDB()) == SQLITE_OK) + if (OpenDB() == SQLITE_OK) { Instance->Log(DEBUG, "Opened sqlite DB: " + host.host); } @@ -311,7 +310,6 @@ class SQLConn : public classbase * * The +1 is for null-terminating the string for mysql_real_escape_string */ - query = new char[req.query.q.length() + (paramlen*2) + 1]; queryend = query; @@ -344,7 +342,6 @@ class SQLConn : public classbase *queryend = 0; req.query.q = query; - //Instance->Log(DEBUG, "<******> Doing query: " + ConvToStr(req.query.q.data())); SQLite3Result* res = new SQLite3Result(mod, req.GetSource(), req.id); res->dbid = host.id; res->query = req.query.q; @@ -356,11 +353,12 @@ class SQLConn : public classbase sqlite3_update_hook(conn, QueryUpdateHook, ¶ms); if (sqlite3_exec(conn, req.query.q.data(), QueryResult, ¶ms, &errmsg) != SQLITE_OK) { - Instance->Log(DEBUG, "Query failed: " + ConvToStr(errmsg)); + std::string error(errmsg); sqlite3_free(errmsg); + Instance->Log(DEBUG, "Query failed: " + ConvToStr(errmsg)); delete[] query; delete res; - return SQLerror(QSEND_FAIL, ConvToStr(errmsg)); + return SQLerror(QSEND_FAIL, error); } Instance->Log(DEBUG, "Dispatched query successfully. ID: %d resulting rows %d", req.id, res->Rows()); delete[] query; -- cgit v1.2.3