From f2f1801c25e3d8d936fcd828a14f5af6d3d862c9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 6 Mar 2014 13:35:42 +0100 Subject: [PATCH] db/proxy: check connect error before initializing SocketMonitor Fixes crash bug because mpd_connection_get_async() was called without a connection. --- src/db/plugins/ProxyDatabasePlugin.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/db/plugins/ProxyDatabasePlugin.cxx b/src/db/plugins/ProxyDatabasePlugin.cxx index e46b4b9e8..0ab25005a 100644 --- a/src/db/plugins/ProxyDatabasePlugin.cxx +++ b/src/db/plugins/ProxyDatabasePlugin.cxx @@ -353,19 +353,19 @@ ProxyDatabase::Connect(Error &error) return false; } + if (!CheckError(connection, error)) { + mpd_connection_free(connection); + connection = nullptr; + + return false; + } + idle_received = unsigned(-1); is_idle = false; SocketMonitor::Open(mpd_async_get_fd(mpd_connection_get_async(connection))); IdleMonitor::Schedule(); - if (!CheckError(connection, error)) { - if (connection != nullptr) - Disconnect(); - - return false; - } - return true; }