Skip to content

Commit

Permalink
cleanup outbox on allocation fail
Browse files Browse the repository at this point in the history
  • Loading branch information
bertmelis committed Aug 30, 2023
1 parent f633972 commit 0975e6b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/MqttClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,24 @@ class MqttClient {
bool _addPacket(Args&&... args) {
espMqttClientTypes::Error error(espMqttClientTypes::Error::SUCCESS);
espMqttClientInternals::Outbox<OutgoingPacket>::Iterator it = _outbox.emplace(0, error, std::forward<Args>(args) ...);
if (it && error == espMqttClientTypes::Error::SUCCESS) return true;
return false;
if (it && error == espMqttClientTypes::Error::SUCCESS) {
return true;
} else {
if (it) _outbox.remove(it);
return false;
}
}

template <typename... Args>
bool _addPacketFront(Args&&... args) {
espMqttClientTypes::Error error(espMqttClientTypes::Error::SUCCESS);
espMqttClientInternals::Outbox<OutgoingPacket>::Iterator it = _outbox.emplaceFront(0, error, std::forward<Args>(args) ...);
if (it && error == espMqttClientTypes::Error::SUCCESS) return true;
return false;
if (it && error == espMqttClientTypes::Error::SUCCESS) {
return true;
} else {
if (it) _outbox.remove(it);
return false;
}
}

void _checkOutbox();
Expand Down

0 comments on commit 0975e6b

Please sign in to comment.