From 38f05de4ca0649259b5dddee558b83e371e0fc85 Mon Sep 17 00:00:00 2001 From: troxor Date: Sat, 27 Apr 2013 23:29:20 -0500 Subject: [PATCH] Quick fix for crashes when mpd stops --- src/libmpdclient.cc | 12 +++++++----- src/mpd.cc | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/libmpdclient.cc b/src/libmpdclient.cc index df7d2d0c..e382fe8c 100644 --- a/src/libmpdclient.cc +++ b/src/libmpdclient.cc @@ -484,10 +484,12 @@ void mpd_clearError(mpd_Connection *connection) void mpd_closeConnection(mpd_Connection *connection) { - closesocket(connection->sock); - free_and_zero(connection->returnElement); - free_and_zero(connection->request); - free(connection); + if (connection) { + closesocket(connection->sock); + free_and_zero(connection->returnElement); + free_and_zero(connection->request); + free(connection); + } WSACleanup(); } @@ -699,7 +701,7 @@ static void mpd_getNextReturnElement(mpd_Connection *connection) void mpd_finishCommand(mpd_Connection *connection) { - while (!connection->doneProcessing) { + while (connection && !connection->doneProcessing) { if (connection->doneListOk) { connection->doneListOk = 0; } diff --git a/src/mpd.cc b/src/mpd.cc index 02bacd7f..4962ec89 100644 --- a/src/mpd.cc +++ b/src/mpd.cc @@ -192,7 +192,7 @@ namespace { mpd_info.status = "MPD not responding"; } mpd_finishCommand(conn); - if (conn->error) { + if (!conn || conn->error) { // fprintf(stderr, "%s\n", conn->errorStr); mpd_closeConnection(conn); conn = 0; @@ -277,7 +277,7 @@ if (b) a=b; else a=""; } } mpd_finishCommand(conn); - if (conn->error) { + if (conn && conn->error) { // fprintf(stderr, "%s\n", conn->errorStr); mpd_closeConnection(conn); conn = 0;