summaryrefslogtreecommitdiff
path: root/plugins/Dbx_sqlite/src/dbevents.cpp
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2018-10-11 00:53:35 +0300
committeraunsane <aunsane@gmail.com>2018-10-11 00:53:57 +0300
commit1724ed49a870a75f7608a8badc2a897ca471203d (patch)
treec4b6406acf45b564ed2ad6ddbe4aad58e72280b7 /plugins/Dbx_sqlite/src/dbevents.cpp
parent9390b42340def16388cd06ab851cc303db0c096e (diff)
dbx_sqlite: fix crash when event's module is wiped after sql statement reset
Diffstat (limited to 'plugins/Dbx_sqlite/src/dbevents.cpp')
-rw-r--r--plugins/Dbx_sqlite/src/dbevents.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/plugins/Dbx_sqlite/src/dbevents.cpp b/plugins/Dbx_sqlite/src/dbevents.cpp
index 0bde038173..3718b37817 100644
--- a/plugins/Dbx_sqlite/src/dbevents.cpp
+++ b/plugins/Dbx_sqlite/src/dbevents.cpp
@@ -51,10 +51,26 @@ void CDbxSQLite::InitEvents()
{
for (size_t i = 0; i < SQL_EVT_STMT_NUM; i++)
sqlite3_prepare_v3(m_db, evt_stmts[i], -1, SQLITE_PREPARE_PERSISTENT, &evt_stmts_prep[i], nullptr);
+
+ sqlite3_stmt *stmt = nullptr;
+ sqlite3_prepare_v2(m_db, "select distinct module from events;", -1, &stmt, nullptr);
+ int rc = 0;
+ while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
+ const char *module = (char*)sqlite3_column_text(stmt, 0);
+ if (mir_strlen(module) > 0)
+ m_modules.insert(mir_strdup(module));
+ }
+ assert(rc == SQLITE_ROW || rc == SQLITE_DONE);
+ sqlite3_finalize(stmt);
}
void CDbxSQLite::UninitEvents()
{
+ for (auto module : m_modules.rev_iter()) {
+ m_modules.removeItem(&module);
+ mir_free(module);
+ }
+
for (size_t i = 0; i < SQL_EVT_STMT_NUM; i++)
sqlite3_finalize(evt_stmts_prep[i]);
}
@@ -131,7 +147,7 @@ MEVENT CDbxSQLite::AddEvent(MCONTACT hContact, DBEVENTINFO *dbei)
sqlite3_bind_int64(stmt, 5, dbei->cbBlob);
sqlite3_bind_blob(stmt, 6, dbei->pBlob, dbei->cbBlob, nullptr);
int rc = sqlite3_step(stmt);
- assert(rc == SQLITE_ROW || rc == SQLITE_DONE);
+ assert(rc == SQLITE_DONE);
sqlite3_reset(stmt);
if (rc != SQLITE_DONE) {
sqlite3_exec(m_db, "rollback;", nullptr, nullptr, nullptr);
@@ -286,7 +302,12 @@ BOOL CDbxSQLite::GetEvent(MEVENT hDbEvent, DBEVENTINFO *dbei)
sqlite3_reset(stmt);
return 1;
}
- dbei->szModule = (char*)sqlite3_column_text(stmt, 0);
+
+ char *module = (char*)sqlite3_column_text(stmt, 0);
+ dbei->szModule = m_modules.find(module);
+ if (dbei->szModule == nullptr)
+ return 1;
+
dbei->timestamp = sqlite3_column_int64(stmt, 1);
dbei->eventType = sqlite3_column_int(stmt, 2);
dbei->flags = sqlite3_column_int64(stmt, 3);