Merge pull request #4695 from Memphiz/badaccess
authorMemphiz <memphis@machzwo.de>
Mon, 12 May 2014 20:37:34 +0000 (22:37 +0200)
committerJonathan Marshall <jmarshall@xbmc.org>
Sat, 17 May 2014 23:22:47 +0000 (11:22 +1200)
[airplay] - fix possible bad access as reported in

xbmc/network/AirPlayServer.cpp
xbmc/network/AirPlayServer.h

index 127a765..8040d9b 100644 (file)
@@ -63,6 +63,7 @@ using namespace ANNOUNCEMENT;
 #define AIRPLAY_STATUS_NOT_IMPLEMENTED     501
 #define AIRPLAY_STATUS_NO_RESPONSE_NEEDED  1000
 
+CCriticalSection CAirPlayServer::ServerInstanceLock;
 CAirPlayServer *CAirPlayServer::ServerInstance = NULL;
 int CAirPlayServer::m_isPlaying = 0;
 
@@ -156,6 +157,8 @@ const char *eventStrings[] = {"playing", "paused", "loading", "stopped"};
 
 void CAirPlayServer::Announce(AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data)
 {
+  CSingleLock lock(ServerInstanceLock);
+
   if ( (flag & Player) && strcmp(sender, "xbmc") == 0 && ServerInstance)
   {
     if (strcmp(message, "OnStop") == 0)
@@ -184,6 +187,8 @@ bool CAirPlayServer::StartServer(int port, bool nonlocal)
 {
   StopServer(true);
 
+  CSingleLock lock(ServerInstanceLock);
+
   ServerInstance = new CAirPlayServer(port, nonlocal);
   if (ServerInstance->Initialize())
   {
@@ -196,6 +201,7 @@ bool CAirPlayServer::StartServer(int port, bool nonlocal)
 
 bool CAirPlayServer::SetCredentials(bool usePassword, const CStdString& password)
 {
+  CSingleLock lock(ServerInstanceLock);
   bool ret = false;
 
   if (ServerInstance)
@@ -214,6 +220,7 @@ bool CAirPlayServer::SetInternalCredentials(bool usePassword, const CStdString&
 
 void CAirPlayServer::StopServer(bool bWait)
 {
+  CSingleLock lock(ServerInstanceLock);
   if (ServerInstance)
   {
     ServerInstance->StopThread(bWait);
@@ -694,13 +701,17 @@ bool CAirPlayServer::CTCPClient::checkAuthorization(const CStdString& authStr,
 
 void CAirPlayServer::backupVolume()
 {
-  if (ServerInstance->m_origVolume == -1)
+  CSingleLock lock(ServerInstanceLock);
+  
+  if (ServerInstance && ServerInstance->m_origVolume == -1)
     ServerInstance->m_origVolume = (int)g_application.GetVolume();
 }
 
 void CAirPlayServer::restoreVolume()
 {
-  if (ServerInstance->m_origVolume != -1 && CSettings::Get().GetBool("services.airplayvolumecontrol"))
+  CSingleLock lock(ServerInstanceLock);
+
+  if (ServerInstance && ServerInstance->m_origVolume != -1 && CSettings::Get().GetBool("services.airplayvolumecontrol"))
   {
     g_application.SetVolume((float)ServerInstance->m_origVolume);
     ServerInstance->m_origVolume = -1;
index 4c486fb..27c7f40 100644 (file)
@@ -112,6 +112,7 @@ private:
   CStdString m_password;
   int m_origVolume;
 
+  static CCriticalSection ServerInstanceLock;
   static CAirPlayServer *ServerInstance;
 };