mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
fix: multiple memory leaks and segfault issues in Flatbuffer Forwarder. (#709)
This commit is contained in:
parent
8db85c9a5a
commit
11a6ff43ae
2
dependencies/external/flatbuffers
vendored
2
dependencies/external/flatbuffers
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 2d5315ff0eebfa4b9c967e708c24be0b21d921b6
|
Subproject commit 8c02d17bea5def5b7006a7290a9f111433d0ab19
|
@ -44,7 +44,7 @@ void FlatBufferClient::readyRead()
|
|||||||
if((uint32_t) _receiveBuffer.size() < messageSize + 4) return;
|
if((uint32_t) _receiveBuffer.size() < messageSize + 4) return;
|
||||||
|
|
||||||
// extract message only and remove header + msg from buffer :: QByteArray::remove() does not return the removed data
|
// extract message only and remove header + msg from buffer :: QByteArray::remove() does not return the removed data
|
||||||
const QByteArray msg = _receiveBuffer.right(messageSize);
|
const QByteArray msg = _receiveBuffer.mid(4, messageSize);
|
||||||
_receiveBuffer.remove(0, messageSize + 4);
|
_receiveBuffer.remove(0, messageSize + 4);
|
||||||
|
|
||||||
const auto* msgData = reinterpret_cast<const uint8_t*>(msg.constData());
|
const auto* msgData = reinterpret_cast<const uint8_t*>(msg.constData());
|
||||||
@ -113,6 +113,8 @@ void FlatBufferClient::registationRequired(const int priority)
|
|||||||
|
|
||||||
// send reply
|
// send reply
|
||||||
sendMessage();
|
sendMessage();
|
||||||
|
|
||||||
|
_builder.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +135,8 @@ void FlatBufferClient::handleRegisterCommand(const hyperionnet::Register *regReq
|
|||||||
|
|
||||||
// send reply
|
// send reply
|
||||||
sendMessage();
|
sendMessage();
|
||||||
|
|
||||||
|
_builder.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatBufferClient::handleImageCommand(const hyperionnet::Image *image)
|
void FlatBufferClient::handleImageCommand(const hyperionnet::Image *image)
|
||||||
@ -192,7 +196,6 @@ void FlatBufferClient::sendMessage()
|
|||||||
_socket->write((const char *) sizeData, sizeof(sizeData));
|
_socket->write((const char *) sizeData, sizeof(sizeData));
|
||||||
_socket->write((const char *)buffer, size);
|
_socket->write((const char *)buffer, size);
|
||||||
_socket->flush();
|
_socket->flush();
|
||||||
_builder.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatBufferClient::sendSuccessReply()
|
void FlatBufferClient::sendSuccessReply()
|
||||||
@ -202,6 +205,8 @@ void FlatBufferClient::sendSuccessReply()
|
|||||||
|
|
||||||
// send reply
|
// send reply
|
||||||
sendMessage();
|
sendMessage();
|
||||||
|
|
||||||
|
_builder.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatBufferClient::sendErrorReply(const std::string &error)
|
void FlatBufferClient::sendErrorReply(const std::string &error)
|
||||||
@ -212,4 +217,6 @@ void FlatBufferClient::sendErrorReply(const std::string &error)
|
|||||||
|
|
||||||
// send reply
|
// send reply
|
||||||
sendMessage();
|
sendMessage();
|
||||||
|
|
||||||
|
_builder.Clear();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ void FlatBufferConnection::readData()
|
|||||||
if((uint32_t) _receiveBuffer.size() < messageSize + 4) return;
|
if((uint32_t) _receiveBuffer.size() < messageSize + 4) return;
|
||||||
|
|
||||||
// extract message only and remove header + msg from buffer :: QByteArray::remove() does not return the removed data
|
// extract message only and remove header + msg from buffer :: QByteArray::remove() does not return the removed data
|
||||||
const QByteArray msg = _receiveBuffer.right(messageSize);
|
const QByteArray msg = _receiveBuffer.mid(4, messageSize);
|
||||||
_receiveBuffer.remove(0, messageSize + 4);
|
_receiveBuffer.remove(0, messageSize + 4);
|
||||||
|
|
||||||
const uint8_t* msgData = reinterpret_cast<const uint8_t*>(msg.constData());
|
const uint8_t* msgData = reinterpret_cast<const uint8_t*>(msg.constData());
|
||||||
@ -117,6 +117,7 @@ void FlatBufferConnection::setColor(const ColorRgb & color, int priority, int du
|
|||||||
|
|
||||||
_builder.Finish(req);
|
_builder.Finish(req);
|
||||||
sendMessage(_builder.GetBufferPointer(), _builder.GetSize());
|
sendMessage(_builder.GetBufferPointer(), _builder.GetSize());
|
||||||
|
_builder.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatBufferConnection::setImage(const Image<ColorRgb> &image)
|
void FlatBufferConnection::setImage(const Image<ColorRgb> &image)
|
||||||
@ -128,6 +129,7 @@ void FlatBufferConnection::setImage(const Image<ColorRgb> &image)
|
|||||||
|
|
||||||
_builder.Finish(req);
|
_builder.Finish(req);
|
||||||
sendMessage(_builder.GetBufferPointer(), _builder.GetSize());
|
sendMessage(_builder.GetBufferPointer(), _builder.GetSize());
|
||||||
|
_builder.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatBufferConnection::clear(int priority)
|
void FlatBufferConnection::clear(int priority)
|
||||||
@ -137,6 +139,7 @@ void FlatBufferConnection::clear(int priority)
|
|||||||
|
|
||||||
_builder.Finish(req);
|
_builder.Finish(req);
|
||||||
sendMessage(_builder.GetBufferPointer(), _builder.GetSize());
|
sendMessage(_builder.GetBufferPointer(), _builder.GetSize());
|
||||||
|
_builder.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FlatBufferConnection::clearAll()
|
void FlatBufferConnection::clearAll()
|
||||||
@ -193,7 +196,6 @@ void FlatBufferConnection::sendMessage(const uint8_t* buffer, uint32_t size)
|
|||||||
count += _socket.write(reinterpret_cast<const char *>(header), 4);
|
count += _socket.write(reinterpret_cast<const char *>(header), 4);
|
||||||
count += _socket.write(reinterpret_cast<const char *>(buffer), size);
|
count += _socket.write(reinterpret_cast<const char *>(buffer), size);
|
||||||
_socket.flush();
|
_socket.flush();
|
||||||
_builder.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FlatBufferConnection::parseReply(const hyperionnet::Reply *reply)
|
bool FlatBufferConnection::parseReply(const hyperionnet::Reply *reply)
|
||||||
|
@ -118,9 +118,9 @@ void MessageForwarder::handlePriorityChanges(const quint8 &priority)
|
|||||||
hyperion::Components activeCompId = _hyperion->getPriorityInfo(priority).componentId;
|
hyperion::Components activeCompId = _hyperion->getPriorityInfo(priority).componentId;
|
||||||
if (activeCompId == hyperion::COMP_GRABBER || activeCompId == hyperion::COMP_V4L)
|
if (activeCompId == hyperion::COMP_GRABBER || activeCompId == hyperion::COMP_V4L)
|
||||||
{
|
{
|
||||||
if ( !obj["proto"].isNull() )
|
if ( !obj["flat"].isNull() )
|
||||||
{
|
{
|
||||||
const QJsonArray & addr = obj["proto"].toArray();
|
const QJsonArray & addr = obj["flat"].toArray();
|
||||||
for (const auto& entry : addr)
|
for (const auto& entry : addr)
|
||||||
{
|
{
|
||||||
addFlatbufferSlave(entry.toString());
|
addFlatbufferSlave(entry.toString());
|
||||||
@ -202,7 +202,7 @@ void MessageForwarder::addFlatbufferSlave(QString slave)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// verify loop with protoserver
|
// verify loop with flatbufserver
|
||||||
const QJsonObject &obj = _hyperion->getSetting(settings::FLATBUFSERVER).object();
|
const QJsonObject &obj = _hyperion->getSetting(settings::FLATBUFSERVER).object();
|
||||||
if(QHostAddress(parts[0]) == QHostAddress::LocalHost && parts[1].toInt() == obj["port"].toInt())
|
if(QHostAddress(parts[0]) == QHostAddress::LocalHost && parts[1].toInt() == obj["port"].toInt())
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user