[vlc-commits] upnp: fix double lock

Thomas Guillem git at videolan.org
Thu Jun 2 10:37:48 CEST 2016


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jun  2 10:01:25 2016 +0200| [e08970c1adebdf497b20110723846c6b27ba08d3] | committer: Thomas Guillem

upnp: fix double lock

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e08970c1adebdf497b20110723846c6b27ba08d3
---

 modules/services_discovery/upnp.cpp |   17 ++++++++---------
 modules/services_discovery/upnp.hpp |    4 ++--
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/modules/services_discovery/upnp.cpp b/modules/services_discovery/upnp.cpp
index bb28aa6..e9dbdda 100644
--- a/modules/services_discovery/upnp.cpp
+++ b/modules/services_discovery/upnp.cpp
@@ -299,11 +299,10 @@ MediaServerList::~MediaServerList()
     vlc_mutex_destroy( &m_lock );
 }
 
-bool MediaServerList::addServer( MediaServerDesc* desc )
+bool MediaServerList::addServerLocked( MediaServerDesc* desc )
 {
-    vlc_mutex_locker lock( &m_lock );
     input_item_t* p_input_item = NULL;
-    if ( getServer( desc->UDN ) )
+    if ( getServerLocked( desc->UDN ) )
         return false;
 
     msg_Dbg( m_sd, "Adding server '%s' with uuid '%s'", desc->friendlyName.c_str(), desc->UDN.c_str() );
@@ -338,7 +337,7 @@ bool MediaServerList::addServer( MediaServerDesc* desc )
     return true;
 }
 
-MediaServerDesc* MediaServerList::getServer( const std::string& udn )
+MediaServerDesc* MediaServerList::getServerLocked( const std::string& udn )
 {
     std::vector<MediaServerDesc*>::const_iterator it = m_list.begin();
     std::vector<MediaServerDesc*>::const_iterator ite = m_list.end();
@@ -419,7 +418,7 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
         }
 
         /* Check if server is already added */
-        if ( getServer( psz_udn ) )
+        if ( getServerLocked( psz_udn ) )
         {
             msg_Warn( m_sd, "Server with uuid '%s' already exists.", psz_udn );
             continue;
@@ -463,7 +462,7 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
                     break;
 
                 p_server->isSatIp = true;
-                if ( !addServer( p_server ) )
+                if ( !addServerLocked( p_server ) )
                     delete p_server;
             } else {
                 /* if no playlist is found, add a playlist from the web based on the chosen
@@ -490,7 +489,7 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
                                                                   psz_friendly_name, psz_url, iconUrl );
 
                 p_server->isSatIp = true;
-                if( !addServer( p_server ) ) {
+                if( !addServerLocked( p_server ) ) {
                     delete p_server;
                 }
                 free( psz_url );
@@ -539,7 +538,7 @@ void MediaServerList::parseNewServer( IXML_Document *doc, const std::string &loc
                     if ( unlikely( !p_server ) )
                         break;
 
-                    if ( !addServer( p_server ) )
+                    if ( !addServerLocked( p_server ) )
                     {
                         delete p_server;
                         continue;
@@ -612,7 +611,7 @@ void MediaServerList::removeServer( const std::string& udn )
 {
     vlc_mutex_locker lock( &m_lock );
 
-    MediaServerDesc* p_server = getServer( udn );
+    MediaServerDesc* p_server = getServerLocked( udn );
     if ( !p_server )
         return;
 
diff --git a/modules/services_discovery/upnp.hpp b/modules/services_discovery/upnp.hpp
index 01bbb23..8e7686b 100644
--- a/modules/services_discovery/upnp.hpp
+++ b/modules/services_discovery/upnp.hpp
@@ -101,9 +101,9 @@ public:
     MediaServerList( services_discovery_t* p_sd );
     ~MediaServerList();
 
-    bool addServer(MediaServerDesc *desc );
+    bool addServerLocked(MediaServerDesc *desc );
     void removeServer(const std::string &udn );
-    MediaServerDesc* getServer( const std::string& udn );
+    MediaServerDesc* getServerLocked( const std::string& udn );
     static int Callback( Upnp_EventType event_type, void* p_event, MediaServerList* self );
 
 private:



More information about the vlc-commits mailing list