[vlc-devel] commit: Do not leak 1 byte per variable created ( Rafaël Carré )

git version control git at videolan.org
Mon May 5 11:39:19 CEST 2008


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Mon May  5 11:40:04 2008 +0200| [2f601f6314210a2ec7af4edd5364d63fbdf56e94]

Do not leak 1 byte per variable created

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

 src/misc/variables.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/misc/variables.c b/src/misc/variables.c
index f4d6edb..2c2a789 100644
--- a/src/misc/variables.c
+++ b/src/misc/variables.c
@@ -53,7 +53,13 @@ static int CmpTime( vlc_value_t v, vlc_value_t w )
 {
     return v.i_time == w.i_time ? 0 : v.i_time > w.i_time ? 1 : -1;
 }
-static int CmpString( vlc_value_t v, vlc_value_t w ) { return strcmp( v.psz_string, w.psz_string ); }
+static int CmpString( vlc_value_t v, vlc_value_t w )
+{
+    if( !v.psz_string )
+        return !w.psz_string ? 0 : -1;
+    else
+        return !w.psz_string ? 1 : strcmp( v.psz_string, w.psz_string );
+}
 static int CmpFloat( vlc_value_t v, vlc_value_t w ) { return v.f_float == w.f_float ? 0 : v.f_float > w.f_float ? 1 : -1; }
 static int CmpAddress( vlc_value_t v, vlc_value_t w ) { return v.p_address == w.p_address ? 0 : v.p_address > w.p_address ? 1 : -1; }
 
@@ -61,7 +67,7 @@ static int CmpAddress( vlc_value_t v, vlc_value_t w ) { return v.p_address == w.
  * Local duplication functions, and local deallocation functions
  *****************************************************************************/
 static void DupDummy( vlc_value_t *p_val ) { (void)p_val; /* unused */ }
-static void DupString( vlc_value_t *p_val ) { p_val->psz_string = strdup( p_val->psz_string ); }
+static void DupString( vlc_value_t *p_val ) { if( p_val->psz_string ) p_val->psz_string = strdup( p_val->psz_string ); }
 
 static void DupList( vlc_value_t *p_val )
 {
@@ -247,7 +253,7 @@ int __var_Create( vlc_object_t *p_this, const char *psz_name, int i_type )
             p_var->pf_cmp = CmpString;
             p_var->pf_dup = DupString;
             p_var->pf_free = FreeString;
-            p_var->val.psz_string = strdup( "" );
+            p_var->val.psz_string = NULL;
             break;
         case VLC_VAR_FLOAT:
             p_var->pf_cmp = CmpFloat;




More information about the vlc-devel mailing list