Ensure logs don't indefinitely append past capacity

Summary:
^

There could be cases, albeit unlikely, that logs could be appended for the current state indefintely that would ultimate fail due to not having enough memory.

This change puts a cap on that.

Reviewed By: mweststrate

Differential Revision: D42313904

fbshipit-source-id: 7fd96be822c9427720bccb41c6c32a39213c7652
This commit is contained in:
Lorenzo Blasa
2023-01-10 06:48:53 -08:00
committed by Facebook GitHub Bot
parent 882b969931
commit a040fb8d4e
2 changed files with 23 additions and 6 deletions

View File

@@ -10,6 +10,7 @@
#include <map>
#include <memory>
#include <mutex>
#include <sstream>
#include <string>
#include <vector>
@@ -53,10 +54,11 @@ class FlipperState {
void success(std::string);
void failed(std::string, std::string);
void started(std::string);
void ensureLogsCapacity();
std::mutex mutex; // Protects all our member variables.
std::shared_ptr<FlipperStateUpdateListener> mListener = nullptr;
std::string logs;
std::stringstream logs;
std::vector<std::string> insertOrder;
std::map<std::string, facebook::flipper::State> stateMap;
};