[vlc-devel] commit: Fix p_libvlc->psz_vlcpath related crash. It showed up with multiple webbrowser plugins on the same webpage. ( Jean-Paul Saman )

git version control git at videolan.org
Mon Oct 27 16:23:27 CET 2008


vlc | branch: 0.8.6-bugfix | Jean-Paul Saman <jpsaman at videolan.org> | Tue Oct 21 10:33:51 2008 +0200| [7bcdb4d9af2056ac0a225210b450d64ae3b91312] | committer: Jean-Paul Saman 

Fix p_libvlc->psz_vlcpath related crash. It showed up with multiple webbrowser plugins on the same webpage.

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

 src/misc/darwin_specific.m |   45 ++++++++++++++++++++++++++++---------------
 src/misc/modules.c         |   26 +++++++++++++++---------
 2 files changed, 45 insertions(+), 26 deletions(-)

diff --git a/src/misc/darwin_specific.m b/src/misc/darwin_specific.m
index 53b1472..90c18e8 100644
--- a/src/misc/darwin_specific.m
+++ b/src/misc/darwin_specific.m
@@ -41,15 +41,15 @@ static int FindLanguage( const char * psz_lang )
     const char ** ppsz_parser;
     const char * ppsz_all[] =
     {
-	"Arabic", "ar",
+        "Arabic", "ar",
         "Catalan", "ca",
-	"Czech", "cs",
+        "Czech", "cs",
         "Danish", "da",
         "German", "de",
         "British", "en_GB",
         "English", "en",
         "Spanish", "es",
-	"Persian", "fa",
+        "Persian", "fa",
         "French", "fr",
         "Galician", "gl",
         "Hebrew", "he",
@@ -60,18 +60,18 @@ static int FindLanguage( const char * psz_lang )
         "Korean", "ko",
         "Georgian", "ka",
         "Malay", "ms",
-	"Nepali", "ne",
-	"Dutch", "nl",
+        "Nepali", "ne",
+        "Dutch", "nl",
         "Occitan", "oc",
-	"Polish", "pl",
-	"Brazilian Portuguese", "pt_BR",
+        "Polish", "pl",
+        "Brazilian Portuguese", "pt_BR",
         "Romanian", "ro",
         "Russian", "ru",
         "Serbian", "sr",
         "Slovak", "sk",
         "Slovenian", "sl",
         "Swedish", "sv",
-	"Thai", "th",
+        "Thai", "th",
         "Turkish", "tr",
         "Simplified Chinese", "zh_CN",
         "Chinese Traditional", "zh_TW",
@@ -94,10 +94,10 @@ static int FindLanguage( const char * psz_lang )
 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
 {
     char i_dummy;
-    char *p_char, *p_oldchar = &i_dummy;
+    char *p_char = NULL, *p_start, *p_oldchar = &i_dummy;
 
     /* Get the full program path and name */
-    p_char = p_this->p_libvlc->psz_vlcpath = strdup( ppsz_argv[ 0 ] );
+    p_char = p_start = strdup( ppsz_argv[ 0 ] );
 
     /* Remove trailing program name */
     for( ; *p_char ; )
@@ -108,12 +108,16 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
             *p_char = '\0';
             p_oldchar = p_char;
         }
-
         p_char++;
     }
 
+    p_this->p_libvlc->psz_vlcpath = strdup( p_start );
+    free( p_start );
+    p_start = NULL;
+
     /* Check if $LANG is set. */
-    if ( (p_char = getenv("LANG")) == NULL )
+    p_char = getenv("LANG");
+    if( p_char == NULL )
     {
         NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
 
@@ -136,7 +140,9 @@ void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
     }
 
     vlc_mutex_init( p_this, &p_this->p_libvlc->iconv_lock );
+    vlc_mutex_lock( &(p_this->p_libvlc->iconv_lock) );
     p_this->p_libvlc->iconv_macosx = vlc_iconv_open( "UTF-8", "UTF-8-MAC" );
+    vlc_mutex_unlock( &(p_this->p_libvlc->iconv_lock) );
 }
 
 /*****************************************************************************
@@ -152,10 +158,17 @@ void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
  *****************************************************************************/
 void system_End( vlc_t *p_this )
 {
-    free( p_this->p_libvlc->psz_vlcpath );
-
+    if( p_this && p_this->p_libvlc )
+    {
+        free( p_this->p_libvlc->psz_vlcpath );
+        p_this->p_libvlc->psz_vlcpath = NULL;
+    }
     if ( p_this->p_libvlc->iconv_macosx != (vlc_iconv_t)-1 )
+    {
+        vlc_mutex_lock( &(p_this->p_libvlc->iconv_lock) );
         vlc_iconv_close( p_this->p_libvlc->iconv_macosx );
-    vlc_mutex_destroy( &p_this->p_libvlc->iconv_lock );
+        p_this->p_libvlc->iconv_macosx = (vlc_iconv_t)-1;
+        vlc_mutex_unlock( &(p_this->p_libvlc->iconv_lock) );
+        vlc_mutex_destroy( &p_this->p_libvlc->iconv_lock );
+    }
 }
-
diff --git a/src/misc/modules.c b/src/misc/modules.c
index 9dc6fec..b65a074 100644
--- a/src/misc/modules.c
+++ b/src/misc/modules.c
@@ -748,7 +748,7 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
 #endif
 
     char **ppsz_path = path;
-    char *psz_fullpath;
+    char *psz_fullpath = NULL;
 
     /* If the user provided a plugin path, we add it to the list */
     path[ sizeof(path)/sizeof(char*) - 2 ] =
@@ -768,21 +768,27 @@ static void AllocateAllPlugins( vlc_object_t *p_this )
         if( (*ppsz_path)[0] != '/' )
 #endif
         {
-            int i_dirlen = strlen( *ppsz_path );
-            i_dirlen += strlen( p_this->p_libvlc->psz_vlcpath ) + 2;
+            int i_ret;
 
-            psz_fullpath = malloc( i_dirlen );
-            if( psz_fullpath == NULL )
+            if( !p_this->p_libvlc->psz_vlcpath )
             {
-                continue;
+                i_ret = asprintf( &psz_fullpath, "%s", *ppsz_path );
             }
+            else
+            {
 #ifdef WIN32
-            sprintf( psz_fullpath, "%s\\%s",
-                     p_this->p_libvlc->psz_vlcpath, *ppsz_path );
+                i_ret = asprintf( &psz_fullpath, "%s\\%s",
+                                  p_this->p_libvlc->psz_vlcpath, *ppsz_path );
 #else
-            sprintf( psz_fullpath, "%s/%s",
-                     p_this->p_libvlc->psz_vlcpath, *ppsz_path );
+                i_ret = asprintf( &psz_fullpath, "%s/%s",
+                                  p_this->p_libvlc->psz_vlcpath, *ppsz_path );
 #endif
+            }
+            if( i_ret < 0 )
+            {
+                psz_fullpath = NULL;
+                continue;
+            }
         }
         else
 #endif




More information about the vlc-devel mailing list