From d7c9eb34f80f207efd47d2fc65e31aedf166c323 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 5 Jun 2021 17:50:34 +0300 Subject: major code cleaning in regard to db_event_getBlobSize & event memory allocation --- plugins/AutoShutdown/src/watcher.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'plugins/AutoShutdown/src/watcher.cpp') diff --git a/plugins/AutoShutdown/src/watcher.cpp b/plugins/AutoShutdown/src/watcher.cpp index e30ab9ad5f..b01cb95735 100644 --- a/plugins/AutoShutdown/src/watcher.cpp +++ b/plugins/AutoShutdown/src/watcher.cpp @@ -91,23 +91,21 @@ static wchar_t* GetMessageText(BYTE **ppBlob, DWORD *pcbBlob) static int MsgEventAdded(WPARAM, LPARAM hDbEvent) { if (currentWatcherType & SDWTF_MESSAGE) { - DBEVENTINFO dbe = {}; - dbe.cbBlob = db_event_getBlobSize(hDbEvent); - dbe.pBlob = (BYTE*)mir_alloc(dbe.cbBlob + 2); /* ensure term zero */ - if (dbe.pBlob == nullptr) + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(hDbEvent, &dbei)) return 0; - if (!db_event_get(hDbEvent, &dbe)) - if (dbe.eventType == EVENTTYPE_MESSAGE && !(dbe.flags & DBEF_SENT)) { - DBVARIANT dbv; - if (!g_plugin.getWString("Message", &dbv)) { - TrimString(dbv.pwszVal); - wchar_t *pszMsg = GetMessageText(&dbe.pBlob, &dbe.cbBlob); - if (pszMsg != nullptr && wcsstr(pszMsg, dbv.pwszVal) != nullptr) - ShutdownAndStopWatcher(); /* msg with specified text recvd */ - mir_free(dbv.pwszVal); /* does NULL check */ - } + + if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_SENT)) { + DBVARIANT dbv; + if (!g_plugin.getWString("Message", &dbv)) { + TrimString(dbv.pwszVal); + wchar_t *pszMsg = GetMessageText(&dbei.pBlob, &dbei.cbBlob); + if (pszMsg != nullptr && wcsstr(pszMsg, dbv.pwszVal) != nullptr) + ShutdownAndStopWatcher(); /* msg with specified text recvd */ + mir_free(dbv.pwszVal); /* does NULL check */ } - mir_free(dbe.pBlob); + } } return 0; } -- cgit v1.2.3