From a50660d96686b0f997c135691d2f74e084dcae2b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 26 Apr 2018 22:43:43 +0200 Subject: [PATCH] Fix a crash if somebody is trying to get metrics (or perhaps also tally) while we are shutting down. --- httpd.cpp | 20 +++++++++++++------- httpd.h | 1 + mixer.cpp | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/httpd.cpp b/httpd.cpp index 9782dca..f644176 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -30,13 +30,7 @@ HTTPD::HTTPD() HTTPD::~HTTPD() { - if (mhd) { - MHD_quiesce_daemon(mhd); - for (Stream *stream : streams) { - stream->stop(); - } - MHD_stop_daemon(mhd); - } + stop(); } void HTTPD::start(int port) @@ -52,6 +46,18 @@ void HTTPD::start(int port) } } +void HTTPD::stop() +{ + if (mhd) { + MHD_quiesce_daemon(mhd); + for (Stream *stream : streams) { + stream->stop(); + } + MHD_stop_daemon(mhd); + mhd = nullptr; + } +} + void HTTPD::add_data(const char *buf, size_t size, bool keyframe, int64_t time, AVRational timebase) { unique_lock lock(streams_mutex); diff --git a/httpd.h b/httpd.h index 1c3c98e..57c649b 100644 --- a/httpd.h +++ b/httpd.h @@ -46,6 +46,7 @@ public: } void start(int port); + void stop(); void add_data(const char *buf, size_t size, bool keyframe, int64_t time, AVRational timebase); int64_t get_num_connected_clients() const { return metric_num_connected_clients.load(); diff --git a/mixer.cpp b/mixer.cpp index a168b66..e66a388 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -499,6 +499,7 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards) Mixer::~Mixer() { + httpd.stop(); BMUSBCapture::stop_bm_thread(); for (unsigned card_index = 0; card_index < num_cards + num_video_inputs + num_html_inputs; ++card_index) { -- 2.39.2