[vlc-devel] commit: Simplify executable name retrieval and fix a memory leak ( Rafaël Carré )

git version control git at videolan.org
Mon May 5 10:40:38 CEST 2008


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Mon May  5 10:41:07 2008 +0200| [aab3bb4e6be21ea3ef8946d5127312ec025a4a6a]

Simplify executable name retrieval and fix a memory leak

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

 src/libvlc-common.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/libvlc-common.c b/src/libvlc-common.c
index f52802f..31f6f69 100644
--- a/src/libvlc-common.c
+++ b/src/libvlc-common.c
@@ -250,18 +250,21 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     /* Get the executable name (similar to the basename command) */
     if( i_argc > 0 )
     {
-        const char *exe = ppsz_argv[0];
-        const char *tmp = exe;
-        while( *exe )
+        const char *psz_exe = ppsz_argv[0] + strlen( ppsz_argv[0] );
+        for( ; psz_exe > ppsz_argv[0] ; psz_exe-- )
         {
-            if( *exe++ == '/' )
-                tmp = exe;
+            if( *psz_exe == '/' )
+            {
+                psz_exe++;
+                break;
+            }
+        }
+
+        if( *psz_exe )
+        {
+            free( p_libvlc->psz_object_name );
+            p_libvlc->psz_object_name = strdup( psz_exe );
         }
-        p_libvlc->psz_object_name = strdup( tmp );
-    }
-    else
-    {
-        p_libvlc->psz_object_name = strdup( "vlc" );
     }
 
     /*




More information about the vlc-devel mailing list