Skip to content

Commit

Permalink
Merge pull request #100 from CapnBry/msp-leaks
Browse files Browse the repository at this point in the history
Don't leak msppacket every Get on HDZero/Skyzone
  • Loading branch information
pkendall64 committed Jul 21, 2023
2 parents f532301 + 99025e9 commit db56cbf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
30 changes: 15 additions & 15 deletions src/hdzero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ uint8_t
HDZero::GetChannelIndex()
{
MSP msp;
mspPacket_t* packet = new mspPacket_t;
packet->reset();
packet->makeCommand();
packet->function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX;
mspPacket_t packet;
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX;

// Send request, then wait for a response back from the VRX
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT);
bool receivedResponse = msp.awaitPacket(&packet, m_port, VRX_RESPONSE_TIMEOUT);

if (receivedResponse)
{
packet = msp.getReceivedPacket();
mspPacket_t *packetResponse = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte();
return packetResponse->readByte();
}

DBGLN("HDZero module: Exceeded timeout while waiting for channel index response");
Expand All @@ -61,19 +61,19 @@ uint8_t
HDZero::GetRecordingState()
{
MSP msp;
mspPacket_t* packet = new mspPacket_t;
packet->reset();
packet->makeCommand();
packet->function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE;
mspPacket_t packet;
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE;

// Send request, then wait for a response back from the VRX
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT);
bool receivedResponse = msp.awaitPacket(&packet, m_port, VRX_RESPONSE_TIMEOUT);

if (receivedResponse)
{
packet = msp.getReceivedPacket();
mspPacket_t *packetResponse = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
return packetResponse->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
}

DBGLN("HDZero module: Exceeded timeout while waiting for recording state response");
Expand Down Expand Up @@ -136,6 +136,6 @@ HDZero::SetRTC()
packet.addByte(timeData.tm_hour);
packet.addByte(timeData.tm_min);
packet.addByte(timeData.tm_sec);

msp.sendPacket(&packet, m_port);
}
28 changes: 14 additions & 14 deletions src/skyzone_msp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ uint8_t
SkyzoneMSP::GetChannelIndex()
{
MSP msp;
mspPacket_t* packet = new mspPacket_t;
packet->reset();
packet->makeCommand();
packet->function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX;
mspPacket_t packet;
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_GET_CHANNEL_INDEX;

// Send request, then wait for a response back from the VRX
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT);
bool receivedResponse = msp.awaitPacket(&packet, m_port, VRX_RESPONSE_TIMEOUT);

if (receivedResponse)
{
packet = msp.getReceivedPacket();
mspPacket_t* packetResponse = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte();
return packetResponse->readByte();
}

DBGLN("Skyzone module: Exceeded timeout while waiting for channel index response");
Expand All @@ -60,19 +60,19 @@ uint8_t
SkyzoneMSP::GetRecordingState()
{
MSP msp;
mspPacket_t* packet = new mspPacket_t;
packet->reset();
packet->makeCommand();
packet->function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE;
mspPacket_t packet;
packet.reset();
packet.makeCommand();
packet.function = MSP_ELRS_BACKPACK_GET_RECORDING_STATE;

// Send request, then wait for a response back from the VRX
bool receivedResponse = msp.awaitPacket(packet, m_port, VRX_RESPONSE_TIMEOUT);
bool receivedResponse = msp.awaitPacket(&packet, m_port, VRX_RESPONSE_TIMEOUT);

if (receivedResponse)
{
packet = msp.getReceivedPacket();
mspPacket_t *packetResponse = msp.getReceivedPacket();
msp.markPacketReceived();
return packet->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
return packetResponse->readByte() ? VRX_DVR_RECORDING_ACTIVE : VRX_DVR_RECORDING_INACTIVE;
}

DBGLN("Skyzone module: Exceeded timeout while waiting for recording state response");
Expand Down

0 comments on commit db56cbf

Please sign in to comment.