Fix use-after-free in log_cat
We were trying to use NodePrinters in the factory after they were
destroyed. Initializing them to outlive the factory addresses this.
Change-Id: I19e5b112fb67ef7d36ff9f885b6497b6abbec313
Signed-off-by: Sanjay Narayanan <sanjay.narayanan@bluerivertech.com>
diff --git a/aos/events/logging/log_cat.cc b/aos/events/logging/log_cat.cc
index 5a9040e..71293af 100644
--- a/aos/events/logging/log_cat.cc
+++ b/aos/events/logging/log_cat.cc
@@ -364,16 +364,15 @@
aos::FastStringBuilder builder;
- aos::SimulatedEventLoopFactory event_loop_factory(reader.configuration());
-
- reader.RegisterWithoutStarting(&event_loop_factory);
-
uint64_t message_print_counter = 0;
std::vector<NodePrinter *> printers;
- printers.resize(
- aos::configuration::NodesCount(event_loop_factory.configuration()),
- nullptr);
+ printers.resize(aos::configuration::NodesCount(reader.configuration()),
+ nullptr);
+
+ aos::SimulatedEventLoopFactory event_loop_factory(reader.configuration());
+
+ reader.RegisterWithoutStarting(&event_loop_factory);
for (const aos::Node *node :
aos::configuration::GetNodes(event_loop_factory.configuration())) {