diff options
author | George Hazan <ghazan@miranda.im> | 2021-06-05 17:50:34 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-06-05 17:50:34 +0300 |
commit | d7c9eb34f80f207efd47d2fc65e31aedf166c323 (patch) | |
tree | 338b9b905674dc31b1efab739dfcedeed3d8d7b3 /plugins/AutoShutdown/src | |
parent | ffc5a3d7550528281976745279e77ac9faba551b (diff) |
major code cleaning in regard to db_event_getBlobSize & event memory allocation
Diffstat (limited to 'plugins/AutoShutdown/src')
-rw-r--r-- | plugins/AutoShutdown/src/watcher.cpp | 28 |
1 files changed, 13 insertions, 15 deletions
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;
}
|