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 --- src/core/stdfile/src/filerecvdlg.cpp | 9 +++------ src/core/stdmsg/src/msglog.cpp | 13 ++++--------- src/core/stduihist/src/history.cpp | 33 ++++++++++----------------------- 3 files changed, 17 insertions(+), 38 deletions(-) (limited to 'src/core') diff --git a/src/core/stdfile/src/filerecvdlg.cpp b/src/core/stdfile/src/filerecvdlg.cpp index d9b54d4f8a..a1e11bafb5 100644 --- a/src/core/stdfile/src/filerecvdlg.cpp +++ b/src/core/stdfile/src/filerecvdlg.cpp @@ -222,12 +222,9 @@ INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l db_event_markRead(dat->hContact, dat->hDbEvent); - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent); - if (dbei.cbBlob > 4 && dbei.cbBlob <= 8196) { - dbei.pBlob = (PBYTE)alloca(dbei.cbBlob + 1); - db_event_get(dat->hDbEvent, &dbei); - dbei.pBlob[dbei.cbBlob] = 0; + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (!db_event_get(dat->hDbEvent, &dbei)) { dat->fs = cle->lParam ? (HANDLE)cle->lParam : (HANDLE)*(PDWORD)dbei.pBlob; char *str = (char*)dbei.pBlob + 4; diff --git a/src/core/stdmsg/src/msglog.cpp b/src/core/stdmsg/src/msglog.cpp index 3161dff215..7905452248 100644 --- a/src/core/stdmsg/src/msglog.cpp +++ b/src/core/stdmsg/src/msglog.cpp @@ -201,17 +201,13 @@ int DbEventIsShown(DBEVENTINFO *dbei) //mir_free() the return value static bool CreateRTFFromDbEvent(LogStreamData *dat) { - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent); - if (dbei.cbBlob == -1) + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (db_event_get(dat->hDbEvent, &dbei)) return false; - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); - db_event_get(dat->hDbEvent, &dbei); - if (!DbEventIsShown(&dbei)) { - mir_free(dbei.pBlob); + if (!DbEventIsShown(&dbei)) return false; - } if (!(dbei.flags & DBEF_SENT) && (dbei.eventType == EVENTTYPE_MESSAGE || DbEventIsForMsgWindow(&dbei))) { db_event_markRead(dat->hContact, dat->hDbEvent); @@ -338,7 +334,6 @@ static bool CreateRTFFromDbEvent(LogStreamData *dat) if (bIsRtl) buf.Append("\\par"); - mir_free(dbei.pBlob); return true; } diff --git a/src/core/stduihist/src/history.cpp b/src/core/stduihist/src/history.cpp index f76bf5c6cb..aadf8491e5 100644 --- a/src/core/stduihist/src/history.cpp +++ b/src/core/stduihist/src/history.cpp @@ -122,19 +122,12 @@ static void FillHistoryThread(THistoryThread *hInfo) int i = db_event_count(hInfo->hContact); SendDlgItemMessage(hInfo->hwnd, IDC_LIST, LB_INITSTORAGE, i, i * 40); - DBEVENTINFO dbei = {}; - int oldBlobSize = 0; - MEVENT hDbEvent = db_event_last(hInfo->hContact); - - while (hDbEvent != NULL) { + DB::ECPTR pCursor(DB::EventsRev(hInfo->hContact)); + while (MEVENT hDbEvent = pCursor.FetchNext()) { if (!IsWindow(hInfo->hwnd)) break; - int newBlobSize = db_event_getBlobSize(hDbEvent); - if (newBlobSize > oldBlobSize) { - dbei.pBlob = (PBYTE)mir_realloc(dbei.pBlob, newBlobSize); - oldBlobSize = newBlobSize; - } - dbei.cbBlob = oldBlobSize; + + DBEVENTINFO dbei = {}; db_event_get(hDbEvent, &dbei); wchar_t str[200], eventText[256], strdatetime[64]; @@ -145,9 +138,7 @@ static void FillHistoryThread(THistoryThread *hInfo) i = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)eventText); SendMessage(hwndList, LB_SETITEMDATA, i, (LPARAM)hDbEvent); } - hDbEvent = db_event_prev(hInfo->hContact, hDbEvent); } - mir_free(dbei.pBlob); SendDlgItemMessage(hInfo->hwnd, IDC_LIST, LB_SETCURSEL, 0, 0); SendMessage(hInfo->hwnd, WM_COMMAND, MAKEWPARAM(IDC_LIST, LBN_SELCHANGE), 0); @@ -281,16 +272,12 @@ static INT_PTR CALLBACK DlgProcHistory(HWND hwndDlg, UINT msg, WPARAM wParam, LP EnableWindow(GetDlgItem(hwndDlg, IDC_DELETEHISTORY), TRUE); MEVENT hDbEvent = SendDlgItemMessage(hwndDlg, IDC_LIST, LB_GETITEMDATA, sel, 0); - DBEVENTINFO dbei = {}; - dbei.cbBlob = db_event_getBlobSize(hDbEvent); - if ((int)dbei.cbBlob != -1) { - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); - if (db_event_get(hDbEvent, &dbei) == 0) { - ptrW wszDescr(DbEvent_GetTextW(&dbei, CP_ACP)); - if (wszDescr) - SetDlgItemText(hwndDlg, IDC_EDIT, wszDescr); - } - mir_free(dbei.pBlob); + DB::EventInfo dbei; + dbei.cbBlob = -1; + if (!db_event_get(hDbEvent, &dbei)) { + ptrW wszDescr(DbEvent_GetTextW(&dbei, CP_ACP)); + if (wszDescr) + SetDlgItemText(hwndDlg, IDC_EDIT, wszDescr); } } return TRUE; -- cgit v1.2.3