[vlc-devel] commit: config: Don't leak dataDir and configDir in dirs_macos. (Pierre d' Herbemont )

git version control git at videolan.org
Thu Dec 10 02:03:06 CET 2009


vlc | branch: master | Pierre d'Herbemont <pdherbemont at free.fr> | Wed Dec  9 17:44:49 2009 +0100| [fb96d6f7f2d17ac9a2f723ba5f2ddde307156b7c] | committer: Pierre d'Herbemont 

config: Don't leak dataDir and configDir in dirs_macos.

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

 src/config/dirs_macos.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/config/dirs_macos.c b/src/config/dirs_macos.c
index ce63003..a7d5e5f 100644
--- a/src/config/dirs_macos.c
+++ b/src/config/dirs_macos.c
@@ -32,15 +32,27 @@
 #include <vlc_charset.h>
 #include <vlc_configuration.h>
 
+static char *configdir = NULL;
+static char *datadir = NULL;
+
+static pthread_once_t once = PTHREAD_ONCE_INIT;
+
+static void init_dirs( void )
+{
+    configdir = config_GetUserDir(VLC_CONFIG_DIR);
+    datadir = config_GetUserDir(VLC_DATA_DIR);
+}
 
 const char *config_GetConfDir( void )
 {
-    return config_GetUserDir (VLC_CONFIG_DIR);
+    pthread_once(&once, init_dirs);
+    return configdir;
 }
 
 const char *config_GetDataDir (void)
 {
-    return config_GetUserDir (VLC_DATA_DIR);
+    pthread_once(&once, init_dirs);
+    return datadir;
 }
 
 static char *config_GetHomeDir (void)
@@ -56,7 +68,7 @@ static char *config_GetHomeDir (void)
 char *config_GetUserDir (vlc_userdir_t type)
 {
     char *psz_dir;
-    const char *psz_parent = config_GetHomeDir ();
+    char *psz_parent = config_GetHomeDir ();
     const char *psz_path;
 
     switch (type)
@@ -98,5 +110,6 @@ char *config_GetUserDir (vlc_userdir_t type)
     }
     if( asprintf( &psz_dir, psz_path, psz_parent ) == -1 )
         psz_dir = NULL;
+    free(psz_parent);
     return psz_dir;
 }




More information about the vlc-devel mailing list