mainapp: Fix potential bus leak

If we allow the event loop to begin processing outstadning bus events
like bus hello, we can end up with a libsystemd bug that leaks handles
to future bus events, causing the watchdog and broker to fill up their
memory spaces.

Change-Id: I642cf6f24e687eac05b60acd0dac008297f20de9
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/mainapp.cpp b/src/mainapp.cpp
index 26a4f39..ef9b353 100644
--- a/src/mainapp.cpp
+++ b/src/mainapp.cpp
@@ -259,6 +259,12 @@
         // Loop until our timer expires and we don't want to continue
         while (!done && (continueAfterTimeout || !watchdog.timerExpired()))
         {
+            // Process all outstanding bus events before running the loop.
+            // This prevents the sd-bus handling logic from leaking memory.
+            // TODO: Remove when upstream fixes this bug
+            while (bus.process_discard() > 0)
+                ;
+
             // Run and never timeout
             event.run(std::nullopt);
         }