diff options
author | George Hazan <ghazan@miranda.im> | 2017-01-08 14:25:25 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-01-08 14:25:25 +0300 |
commit | d56db3273b7e5ebe7d72fd11c6aec80dd497c1be (patch) | |
tree | 93ba7b3731cfb906f58adc56ebbad74ddb91e667 /protocols/Discord | |
parent | f1a204292b895a94f142c32b2f3dc69fcc053e67 (diff) |
fix for data allocation
Diffstat (limited to 'protocols/Discord')
-rw-r--r-- | protocols/Discord/src/gateway.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/protocols/Discord/src/gateway.cpp b/protocols/Discord/src/gateway.cpp index db07b18069..43c923ff00 100644 --- a/protocols/Discord/src/gateway.cpp +++ b/protocols/Discord/src/gateway.cpp @@ -212,6 +212,7 @@ void CDiscordProto::GatewayThreadWorker() dataBufSize = bufSize - headerSize; } else { + bDataBufAllocated = true; size_t newSize = dataBufSize + bufSize - headerSize; dataBuf = (char*)mir_realloc(dataBuf, newSize+1); memcpy(dataBuf + dataBufSize, buf + headerSize, bufSize - headerSize); @@ -233,10 +234,6 @@ void CDiscordProto::GatewayThreadWorker() JSONNode root = JSONNode::parse(dataBuf); if (root) GatewayProcess(root); - if (bDataBufAllocated) - mir_free(dataBuf); - dataBuf = NULL; - dataBufSize = 0; } break; @@ -250,6 +247,13 @@ void CDiscordProto::GatewayThreadWorker() Netlib_Send(m_hGatewayConnection, (char*)buf + headerSize, bufSize - headerSize, 0); break; } + + if (bIsFinal) { + if (bDataBufAllocated) + mir_free(dataBuf); + dataBuf = NULL; + dataBufSize = 0; + } } Netlib_CloseHandle(m_hGatewayConnection); @@ -315,7 +319,7 @@ void CDiscordProto::GatewaySendIdentify() Miranda_GetVersionText(szVersion, _countof(szVersion)); JSONNode props; props.set_name("properties"); - props << WCHAR_PARAM("os", wszOs) << CHAR_PARAM("browser", "Chrome") << CHAR_PARAM("device", "Miranda NG") + props << WCHAR_PARAM("os", wszOs) << CHAR_PARAM("browser", "Chrome") << CHAR_PARAM("device", szVersion) << CHAR_PARAM("referrer", "http://miranda-ng.org") << CHAR_PARAM("referring_domain", "miranda-ng.org"); JSONNode payload; payload.set_name("d"); |