From 26abd0f6c46db9183fc07abe92b3f4776a13952f Mon Sep 17 00:00:00 2001
From: patrick96
Date: Wed, 31 Jan 2018 09:45:29 +0100
Subject: [PATCH] fix(mpd): Check m_status before dereferencing it
This bug was introduced in 645a3142a19747c252d24cc71414d40a8eb5f7dc
Fixes #979
---
include/modules/mpd.hpp | 6 ++++++
src/modules/mpd.cpp | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/modules/mpd.hpp b/include/modules/mpd.hpp
index bd010020..3e94bee8 100644
--- a/include/modules/mpd.hpp
+++ b/include/modules/mpd.hpp
@@ -64,6 +64,12 @@ namespace modules {
static constexpr const char* EVENT_SEEK{"mpdseek"};
unique_ptr m_mpd;
+
+ /*
+ * Stores the mpdstatus instance for the current connection
+ * m_status is not initialized if mpd is not connect, you always have to
+ * make sure that m_status is not NULL before dereferencing it
+ */
unique_ptr m_status;
string m_host{"127.0.0.1"};
diff --git a/src/modules/mpd.cpp b/src/modules/mpd.cpp
index 3d67bc3b..515d402b 100644
--- a/src/modules/mpd.cpp
+++ b/src/modules/mpd.cpp
@@ -200,7 +200,7 @@ namespace modules {
}
}
- if (m_status->match_state(mpdstate::PLAYING)) {
+ if (m_status && m_status->match_state(mpdstate::PLAYING)) {
// Always update the status while playing
m_status->update(-1, m_mpd.get());
}