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 --- protocols/Discord/src/dispatch.cpp | 6 ++---- protocols/Discord/src/proto.cpp | 10 ++++------ 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'protocols/Discord/src') diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp index 4f2d25d35d..6cdef5e4de 100644 --- a/protocols/Discord/src/dispatch.cpp +++ b/protocols/Discord/src/dispatch.cpp @@ -390,9 +390,8 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) if (!bIsNew) { MEVENT hOldEvent = db_event_getById(m_szModuleName, szMsgId); if (hOldEvent) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hOldEvent); - dbei.pBlob = (BYTE*)mir_alloc(dbei.cbBlob); + DB::EventInfo dbei; + dbei.cbBlob = -1; if (!db_event_get(hOldEvent, &dbei)) { ptrW wszOldText(DbEvent_GetTextW(&dbei, CP_UTF8)); if (wszOldText) @@ -400,7 +399,6 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot, bool bIsNew) if (dbei.flags & DBEF_SENT) bOurMessage = true; } - mir_free(dbei.pBlob); } } diff --git a/protocols/Discord/src/proto.cpp b/protocols/Discord/src/proto.cpp index c8304b6375..e5a62df682 100644 --- a/protocols/Discord/src/proto.cpp +++ b/protocols/Discord/src/proto.cpp @@ -374,9 +374,8 @@ int CDiscordProto::AuthRecv(MCONTACT, PROTORECVEVENT *pre) int CDiscordProto::Authorize(MEVENT hDbEvent) { - DBEVENTINFO dbei = {}; - if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) return 1; - if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == nullptr) return 1; + DB::EventInfo dbei; + dbei.cbBlob = -1; if (db_event_get(hDbEvent, &dbei)) return 1; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1; if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1; @@ -390,9 +389,8 @@ int CDiscordProto::Authorize(MEVENT hDbEvent) int CDiscordProto::AuthDeny(MEVENT hDbEvent, const wchar_t*) { - DBEVENTINFO dbei = {}; - if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) return 1; - if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == nullptr) return 1; + DB::EventInfo dbei; + dbei.cbBlob = -1; if (db_event_get(hDbEvent, &dbei)) return 1; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1; if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1; -- cgit v1.2.3