-
Hello :) I am building a C++ windows app that use msquic as client, and a go app that serve a quic server I build my c++ client with cmake, CMAKE_GENERATOR "Visual Studio 17 2022" When i build and run in Release mode, it works. But when i do it in Debug mode, my server receive a packet length of : 3722304989 (it is normally 10 or 11 bytes) I read that : "The value 3722304989 in hexadecimal is 0xDDDDDDDD, which is a common pattern used by some debug memory allocators to fill uninitialized memory." am i doing something wrong ? here is how i send data : bool QuicClient::sendData(const QByteArray &data, const HQUIC &stream, int screenIndex)
{
QUIC_STATUS status;
QByteArray prefixedData;
QDataStream prefixStream(&prefixedData, QIODevice::WriteOnly);
prefixStream.setByteOrder(QDataStream::BigEndian);
quint32 dataSize = static_cast<quint32>(data.size());
quint32 screenIndexUint = static_cast<quint32>(screenIndex);
// Write data length (4 bytes)
prefixStream << dataSize;
// Write screen index (4 bytes)
prefixStream << screenIndexUint;
// Append the actual msgpack data
prefixedData.append(data);
QUIC_BUFFER *buffer = new QUIC_BUFFER();
buffer->Buffer = reinterpret_cast<uint8_t *>(const_cast<char *>(prefixedData.constData()));
buffer->Length = prefixedData.size();
if (QUIC_FAILED(status = msQuicApi->StreamSend(stream, buffer, 1, QUIC_SEND_FLAG_ALLOW_0_RTT, nullptr)))
{
qDebug() << "Failed to send data with status:" << status;
return false;
}
return true;
} Thanks for your help |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
Beta Was this translation helpful? Give feedback.
-
Thanks you @nibanks, now it works in debug ! //edited, wrong code |
Beta Was this translation helpful? Give feedback.
-
So i have done like this to handle pending change and it works if you have any recommendation @nibanks, i am listening, thanks Sending : uint64_t sendId = nextSendId++;
// Create a new PendingSend object
PendingSend pendingSend;
pendingSend.buffer = new QUIC_BUFFER();
pendingSend.buffer->Buffer = reinterpret_cast<uint8_t *>(const_cast<char *>(prefixedData.constData()));
pendingSend.buffer->Length = prefixedData.size();
pendingSend.data = prefixedData; // Store a copy of the data
// Store the PendingSend object in the map
pendingSends[sendId] = std::move(pendingSend);
if (QUIC_FAILED(status = msQuicApi->StreamSend(stream, pendingSends[sendId].buffer, 1, QUIC_SEND_FLAG_ALLOW_0_RTT, reinterpret_cast<void *>(sendId))))
{
qDebug() << "Failed to send data with status:" << status;
delete pendingSends[sendId].buffer;
pendingSends.remove(sendId);
return false;
} send complete : case QUIC_STREAM_EVENT_SEND_COMPLETE:
{
uint64_t sendId = reinterpret_cast<uint64_t>(event->SEND_COMPLETE.ClientContext);
auto it = client->pendingSends.find(sendId);
if (it != client->pendingSends.end())
{
delete it->buffer; // Free the QUIC_BUFFER
client->pendingSends.erase(it); // Remove from map, which will also free the QByteArray
// qDebug() << "Send completed for sendId:" << sendId;
}
else
{
qDebug() << "Received SEND_COMPLETE for unknown sendId:" << sendId;
}
} |
Beta Was this translation helpful? Give feedback.
prefixedData
is a local variable in this function and does not stay allocated for the lifetime of theStreamSend
. The API call returns PENDING, and you need to keep thebuffer
and all memory it points to allocated until you get aSEND_COMPLETE
event for this. Currently, you return immediately and free the memory. So MsQuic ends doing a use-after-free and tries to send junk...