summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src/dbevents.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-28 23:10:50 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-28 23:10:50 +0300
commit098d46fbf4a61d2be79817f05fedc55801d7aa68 (patch)
treeb96c551c522d7bab41330b89ecd5c6ffc77e67f4 /plugins/Dbx_mdbx/src/dbevents.cpp
parentdcd16671be887922a68edc4e5020fdc8fe4a6dd1 (diff)
fix for losing info due to MDBX_RESERVE flag
Diffstat (limited to 'plugins/Dbx_mdbx/src/dbevents.cpp')
-rw-r--r--plugins/Dbx_mdbx/src/dbevents.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/plugins/Dbx_mdbx/src/dbevents.cpp b/plugins/Dbx_mdbx/src/dbevents.cpp
index 572c193475..4ad32afe54 100644
--- a/plugins/Dbx_mdbx/src/dbevents.cpp
+++ b/plugins/Dbx_mdbx/src/dbevents.cpp
@@ -87,16 +87,16 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
MEVENT dwEventId = InterlockedIncrement(&m_dwMaxEventId);
{
- txn_ptr trnlck(StartTran());
-
- MDBX_val key = { &dwEventId, sizeof(MEVENT) }, data = { nullptr, sizeof(DBEvent) + dbe.cbBlob };
- if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
- return 0;
-
- DBEvent *pNewEvent = (DBEvent*)data.iov_base;
+ BYTE *recBuf = (BYTE*)_alloca(sizeof(DBEvent) + dbe.cbBlob);
+ DBEvent *pNewEvent = (DBEvent*)recBuf;
*pNewEvent = dbe;
memcpy(pNewEvent + 1, pBlob, dbe.cbBlob);
+ txn_ptr trnlck(StartTran());
+ MDBX_val key = { &dwEventId, sizeof(MEVENT) }, data = { recBuf, sizeof(DBEvent) + dbe.cbBlob };
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
+ return 0;
+
// add a sorting key
DBEventSortingKey key2 = { contactID, dwEventId, dbe.timestamp };
key.iov_len = sizeof(key2); key.iov_base = &key2;
@@ -106,7 +106,7 @@ STDMETHODIMP_(MEVENT) CDbxMDBX::AddEvent(MCONTACT contactID, DBEVENTINFO *dbei)
cc->Advance(dwEventId, dbe);
if (contactID != 0) {
- MDBX_val keyc = { &contactID, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
+ MDBX_val keyc = { &contactID, sizeof(MCONTACT) }, datac = { &cc->dbc, sizeof(DBContact) };
if (mdbx_put(trnlck, m_dbContacts, &keyc, &datac, 0) != MDBX_SUCCESS)
return 0;
@@ -319,15 +319,17 @@ STDMETHODIMP_(BOOL) CDbxMDBX::MarkEventRead(MCONTACT contactID, MEVENT hDbEvent)
if (cdbe->markedRead())
return cdbe->flags;
- DBEventSortingKey keyVal = { contactID, hDbEvent, cdbe->timestamp };
- if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_RESERVE) != MDBX_SUCCESS)
- return -1;
+ void *recBuf = _alloca(data.iov_len);
+ memcpy(recBuf, data.iov_base, data.iov_len);
+ data.iov_base = recBuf;
DBEvent *pNewEvent = (DBEvent*)data.iov_base;
- *pNewEvent = *cdbe;
-
wRetVal = (pNewEvent->flags |= DBEF_READ);
+ DBEventSortingKey keyVal = { contactID, hDbEvent, cdbe->timestamp };
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
+ return -1;
+
FindNextUnread(trnlck, cc, keyVal);
key.iov_len = sizeof(MCONTACT); key.iov_base = &contactID;
data.iov_base = &cc->dbc; data.iov_len = sizeof(cc->dbc);