Open alprist opened 5 years ago
Hi @alprist
Thanks for the help :+1:
I can copy-paste the code you suggested or you can create a PR (you will be automaically added to the contributors list in such case). Which option do you prefer? =)
Fixed
Hi @cas4ey I have looked at your fix and noticed that you have high possibility to corrupt memory: https://github.com/yse/easy_profiler/blob/develop/profiler_gui/socket_listener.cpp
char* buffer = new char[buffer_size];
...
while (bytes < sizeof(profiler::net::Message))
{
int receivedBytes = m_easySocket.receive(buffer + seek + bytes, buffer_size);
if (receivedBytes < 1)
{
bytes = receivedBytes;
break;
}
bytes += receivedBytes;
}
...
case profiler::net::MessageType::Reply_Blocks:
{
qInfo() << "Receive MessageType::Reply_Blocks";
while (bytes < sizeof(profiler::net::DataMessage))
{
int receivedBytes = m_easySocket.receive(buffer + seek + bytes, buffer_size);
The buffer capacity is buffer_size but you shift its pointer on (seek + bytes). So you cannot read full buffer capacity.
Sometimes the profiler_gui cannot capture data from profiled application. Also sometimes it is not possible to connect to device. The problem was inspected on all versions from the 1.1.0 to 2.0.1 (and later, to master) versions. May be the problem was before but I tried only from 1.1.0. I used it on Android devices.
The reason is the SocketListener::listenCapture method realization. It tries to read the header and assumes that it will have all bytes. But sometimes it may have not enough amount. So it need to save the read data and try to read later. But is doesn't. It always starts to fill its' buffer from start.
bytes = m_easySocket.receive(buffer, buffer_size);
The same situation when it tries to read reply blocks.
So I rewrote the method and it started to work properly:
Please could you look at the code and make appropriate fix?