Create a function to free the memory allocated when calling
authorRémi Duraffort <ivoire@videolan.org>
Tue, 19 May 2009 17:51:02 +0000 (19:51 +0200)
committerRémi Duraffort <ivoire@videolan.org>
Wed, 20 May 2009 17:36:49 +0000 (19:36 +0200)
var_Change(VLC_VAR_GETCHOICES). The memory was freed by a call to
var_Change(VLC_VAR_FREELIST). That's not a good idea as we were doing a lookup
just to free some memory.

22 files changed:
include/vlc_variables.h
modules/access/v4l2.c
modules/control/hotkeys.c
modules/control/http/mvar.c
modules/control/rc.c
modules/demux/ts.c
modules/gui/beos/InterfaceWindow.cpp
modules/gui/macosx/controls.m
modules/gui/ncurses.c
modules/gui/qt4/components/extended_panels.cpp
modules/gui/qt4/input_manager.cpp
modules/gui/qt4/menus.cpp
modules/gui/wince/menus.cpp
modules/misc/lua/libs/variables.c
modules/misc/testsuite/test4.c
src/control/audio.c
src/control/media_player.c
src/control/video.c
src/input/es_out.c
src/input/input.c
src/libvlccore.sym
src/misc/variables.c

index a7ce058..2261c82 100644 (file)
 #define VLC_VAR_GETCHOICES          0x0024
 #define VLC_VAR_FREECHOICES         0x0025
 #define VLC_VAR_GETLIST             0x0026
-#define VLC_VAR_FREELIST            0x0027
-#define VLC_VAR_CHOICESCOUNT        0x0028
+#define VLC_VAR_CHOICESCOUNT        0x0027
 
 #define VLC_VAR_INHERITVALUE        0x0030
 
@@ -134,6 +133,8 @@ VLC_EXPORT( int, var_GetChecked, ( vlc_object_t *, const char *, int, vlc_value_
 #define var_Command(a,b,c,d,e) __var_Command( VLC_OBJECT( a ), b, c, d, e )
 VLC_EXPORT( int, __var_Command, ( vlc_object_t *, const char *, const char *, const char *, char ** ) );
 
+VLC_EXPORT( void, var_FreeList, ( vlc_value_t *, vlc_value_t * ) );
+
 /**
  * __var_Create() with automatic casting.
  */
index 27c139f..705eb66 100644 (file)
@@ -2920,7 +2920,7 @@ static void SetAvailControlsByString( vlc_object_t *p_obj, demux_sys_t *p_sys,
             psz_parser = ( *psz_delim ) ? ( psz_delim + 1 ) : psz_delim;
         }
     }
-    var_Change( p_obj, "allcontrols", VLC_VAR_FREELIST, &val, &text );
+    var_FreeList( &val, &text );
 }
 
 /*****************************************************************************
index 0604bea..ee4757d 100644 (file)
@@ -541,7 +541,7 @@ static void Run( intf_thread_t *p_intf )
                                      _("Aspect ratio: %s"),
                                      text_list.p_list->p_values[i].psz_string );
 
-                    var_Change( p_vout, "aspect-ratio", VLC_VAR_FREELIST, &val_list, &text_list );
+                    var_FreeList( &val_list, &text_list );
                 }
                 free( val.psz_string );
             }
@@ -569,7 +569,7 @@ static void Run( intf_thread_t *p_intf )
                                      _("Crop: %s"),
                                      text_list.p_list->p_values[i].psz_string );
 
-                    var_Change( p_vout, "crop", VLC_VAR_FREELIST, &val_list, &text_list );
+                    var_FreeList( &val_list, &text_list );
                 }
                 free( val.psz_string );
             }
@@ -636,7 +636,7 @@ static void Run( intf_thread_t *p_intf )
                                      _("Deinterlace mode: %s"),
                                      text_list.p_list->p_values[i].psz_string );
 
-                    var_Change( p_vout, "deinterlace", VLC_VAR_FREELIST, &val_list, &text_list );
+                    var_FreeList( &val_list, &text_list );
                 }
                 free( val.psz_string );
             }
@@ -668,7 +668,7 @@ static void Run( intf_thread_t *p_intf )
                                      _("Zoom mode: %s"),
                                 text_list.p_list->p_values[i].var.psz_name );
 
-                    var_Change( p_vout, "zoom", VLC_VAR_FREELIST, &val_list, &text_list );
+                    var_FreeList( &val_list, &text_list );
                 }
             }
             else if( i_action == ACTIONID_CROP_TOP && p_vout )
index c25dd34..2cef899 100644 (file)
@@ -450,8 +450,7 @@ mvar_t *mvar_InputVarSetNew( intf_thread_t *p_intf, char *name,
     }
     /* clean up everything */
     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
-    var_Change( p_sys->p_input, psz_variable, VLC_VAR_FREELIST, &val_list,
-                &text_list );
+    var_FreeList( &val_list, &text_list );
     return s;
 }
 
index 1303d21..cb8c237 100644 (file)
@@ -1153,8 +1153,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
                             &val_list, NULL );
                 msg_rc( "Currently playing chapter %d/%d.",
                         val.i_int, val_list.p_list->i_count );
-                var_Change( p_this, "chapter", VLC_VAR_FREELIST,
-                            &val_list, NULL );
+                var_FreeList( &val_list, NULL );
             }
         }
         else if( !strcmp( psz_cmd, "chapter_n" ) )
@@ -1186,8 +1185,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
                             &val_list, NULL );
                 msg_rc( "Currently playing title %d/%d.",
                         val.i_int, val_list.p_list->i_count );
-                var_Change( p_this, "title", VLC_VAR_FREELIST,
-                            &val_list, NULL );
+                var_FreeList( &val_list, NULL );
             }
         }
         else if( !strcmp( psz_cmd, "title_n" ) )
@@ -1262,8 +1260,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
                     msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
                             text.p_list->p_values[i].psz_string );
             }
-            var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
-                        &val, &text );
+            var_FreeList( &val, &text );
             msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
             free( val_name.psz_string );
@@ -1792,8 +1789,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
             }
             free( psz_value );
         }
-        var_Change( p_vout, psz_variable, VLC_VAR_FREELIST,
-                    &val, &text );
+        var_FreeList( &val, &text );
         msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
         free( val_name.psz_string );
@@ -1880,8 +1876,7 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
                 msg_rc( "| %i - %s", val.p_list->p_values[i].i_int,
                         text.p_list->p_values[i].psz_string );
         }
-        var_Change( (vlc_object_t *)p_aout, psz_variable, VLC_VAR_FREELIST,
-                    &val, &text );
+        var_FreeList( &val, &text );
         msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
         free( val_name.psz_string );
index 180507a..a2b4ef3 100644 (file)
@@ -843,7 +843,7 @@ static void Close( vlc_object_t *p_this )
     {
         vlc_value_t val;
         val.p_list = p_sys->p_programs_list;
-        var_Change( p_demux, "programs", VLC_VAR_FREELIST, &val, NULL );
+        var_FreeList( &val, NULL );
     }
 
     /* If in dump mode, then close the file */
index 12220de..ec92a03 100644 (file)
@@ -671,13 +671,11 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                                 &val_list, NULL );
                     if( val_list.p_list->i_count > val.i_int )
                     {
-                        var_Change( p_input, "chapter", VLC_VAR_FREELIST,
-                                    &val_list, NULL );
+                        var_FreeList( &val_list, NULL );
                         var_SetVoid( p_input, "next-chapter" );
                         break;
                     }
-                    var_Change( p_input, "chapter", VLC_VAR_FREELIST,
-                                &val_list, NULL );
+                    var_FreeList( &val_list, NULL );
                 }
 
                 /* Try to go to next title */
@@ -687,13 +685,11 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
                                 &val_list, NULL );
                     if( val_list.p_list->i_count > val.i_int )
                     {
-                        var_Change( p_input, "title", VLC_VAR_FREELIST,
-                                    &val_list, NULL );
+                        var_FreeList( &val_list, NULL );
                         var_SetVoid( p_input, "next-title" );
                         break;
                     }
-                    var_Change( p_input, "title", VLC_VAR_FREELIST,
-                                &val_list, NULL );
+                    var_FreeList( &val_list, NULL );
                 }
 
                 /* Try to go to next file */
@@ -1264,7 +1260,7 @@ void LanguageMenu::AttachedToWindow()
         }
         AddItem( item );
     }
-    var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
+    var_FreeList( &val_list, &text_list );
 
     vlc_object_release( p_input );
 
@@ -1327,8 +1323,7 @@ void TitleMenu::AttachedToWindow()
             AddItem( item );
         }
 
-        var_Change( p_input, "title", VLC_VAR_FREELIST,
-                    &val_list, &text_list );
+        var_FreeList( &val_list, &text_list );
     }
     vlc_object_release( p_input );
     BMenu::AttachedToWindow();
@@ -1391,8 +1386,7 @@ void ChapterMenu::AttachedToWindow()
             AddItem( item );
         }
 
-        var_Change( p_input, "chapter", VLC_VAR_FREELIST,
-                    &val_list, &text_list );
+        var_FreeList( &val_list, &text_list );
     }
     vlc_object_release( p_input );
     BMenu::AttachedToWindow();
index 084c7f1..88a6b00 100644 (file)
 
     /* clean up everything */
     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
-    var_Change( p_object, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list );
+    var_FreeList( &val_list, &text_list );
 }
 
 - (IBAction)toggleVar:(id)sender
index d2f8ec8..ece4602 100644 (file)
@@ -1559,7 +1559,7 @@ static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
                 {
                     mvnprintw( y++, 0, COLS, _(" Title    : %d/%d"), val.i_int, val_list.p_list->i_count );
                 }
-                var_Change( p_input, "title", VLC_VAR_FREELIST, &val_list, NULL );
+                var_FreeList( &val_list, NULL );
             }
 
             /* Chapter */
@@ -1570,7 +1570,7 @@ static void Redraw( intf_thread_t *p_intf, time_t *t_last_refresh )
                 {
                     mvnprintw( y++, 0, COLS, _(" Chapter  : %d/%d"), val.i_int, val_list.p_list->i_count );
                 }
-                var_Change( p_input, "chapter", VLC_VAR_FREELIST, &val_list, NULL );
+                var_FreeList( &val_list, NULL );
             }
         }
         else
index 464c27f..c2d516e 100644 (file)
@@ -692,8 +692,7 @@ void ExtV4l2::Refresh( void )
                             if( i_val == val2.p_list->p_values[j].i_int )
                                 combobox->setCurrentIndex( j );
                         }
-                        var_Change( p_obj, psz_var, VLC_VAR_FREELIST,
-                                    &val2, &text2 );
+                        var_FreeList( &val2, &text2 );
 
                         CONNECT( combobox, currentIndexChanged( int ), this,
                                  ValueChange( int ) );
@@ -758,7 +757,7 @@ void ExtV4l2::Refresh( void )
             }
             free( name.psz_string );
         }
-        var_Change( p_obj, "controls", VLC_VAR_FREELIST, &val, &text );
+        var_FreeList( &val, &text );
         vlc_object_release( p_obj );
     }
     else
index fd2381a..82bdb04 100644 (file)
@@ -692,7 +692,7 @@ void InputManager::sectionMenu()
             if( !strcmp( text.p_list->p_values[i].psz_string, "Title" ) )
                 root = i;
         }
-        var_Change( p_input, "title  0", VLC_VAR_FREELIST, &val, &text );
+        var_FreeList( &val, &text );
 
         var_SetInteger( p_input, "title  0", root );
     }
@@ -760,7 +760,7 @@ void InputManager::activateTeletext( bool b_enable )
                 i = 0;
             var_SetInteger( p_input, "spu-es", b_enable ? list.p_list->p_values[i].i_int : -1 );
         }
-        var_Change( p_input, "teletext-es", VLC_VAR_FREELIST, &list, &text );
+        var_FreeList( &list, &text );
     }
 }
 
index 0a12c20..387f5b8 100644 (file)
@@ -1129,7 +1129,7 @@ static bool IsMenuEmpty( const char *psz_var,
     }
 
     /* clean up everything */
-    var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
 
     return i_result;
 }
@@ -1344,7 +1344,7 @@ int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,
     currentGroup = NULL;
 
     /* clean up everything */
-    var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
+    var_FreeList( &val_list, &text_list );
 
 #undef CURVAL
 #undef CURTEXT
index 3cebdc7..2c3326b 100644 (file)
@@ -688,7 +688,7 @@ HMENU CreateChoicesMenu( intf_thread_t *p_intf,
 
     /* Clean up everything */
     if( (i_type & VLC_VAR_TYPE) == VLC_VAR_STRING ) free( val.psz_string );
-    var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );
+    var_FreeList( &val_list, &text_list );
 
     return hSubMenu;
 }
index 16833bc..15e8649 100644 (file)
@@ -200,7 +200,7 @@ static int vlclua_var_get_list( lua_State *L )
     if( i_ret < 0 ) return vlclua_push_ret( L, i_ret );
     vlclua_pushvalue( L, VLC_VAR_LIST, val );
     vlclua_pushvalue( L, VLC_VAR_LIST, text );
-    var_Change( *pp_obj, psz_var, VLC_VAR_FREELIST, &val, &text );
+    var_FreeList( &val, &text );
     return 2;
 }
 
index a7280a5..84b393f 100644 (file)
@@ -123,7 +123,7 @@ static int Foo( vlc_object_t *p_this, char const *psz_cmd,
     {
         printf( "value %i: %s\n", i, val.p_list->p_values[i].psz_string );
     }
-    var_Change( p_this, "honk", VLC_VAR_FREELIST, &val, NULL );
+    var_FreeList( &val, NULL );
 
     var_Destroy( p_this, "honk" );
 
index e33c264..5ef62c2 100644 (file)
@@ -380,7 +380,7 @@ int libvlc_audio_get_track_count( libvlc_media_player_t *p_mi,
 
     var_Change( p_input_thread, "audio-es", VLC_VAR_GETCHOICES, &val_list, NULL );
     i_track_count = val_list.p_list->i_count;
-    var_Change( p_input_thread, "audio-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
 
     vlc_object_release( p_input_thread );
     return i_track_count;
@@ -429,7 +429,7 @@ int libvlc_audio_get_track( libvlc_media_player_t *p_mi,
             break;
         }
     }
-    var_Change( p_input_thread, "audio-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );
     return i_track;
 }
@@ -461,7 +461,7 @@ void libvlc_audio_set_track( libvlc_media_player_t *p_mi, int i_track,
         libvlc_exception_raise( p_e, "Setting audio track failed" );
 
 end:
-    var_Change( p_input_thread, "audio-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );
 }
 
index 389fce9..126eef9 100644 (file)
@@ -1177,7 +1177,7 @@ libvlc_track_description_t *
 
     if( val_list.p_list->i_count <= 0 ) /* no tracks */
     {
-        var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list);
+        var_FreeList( &val_list, &text_list);
         return NULL;
     }
 
@@ -1186,8 +1186,7 @@ libvlc_track_description_t *
         malloc( sizeof( libvlc_track_description_t ) );
     if ( !p_track_description )
     {
-        var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
-                    &val_list, &text_list);
+        var_FreeList( &val_list, &text_list);
         vlc_object_release( p_input );
         libvlc_exception_raise( p_e, "no enough memory" );
         return NULL;
@@ -1203,8 +1202,7 @@ libvlc_track_description_t *
             if ( !p_actual )
             {
                 libvlc_track_description_release( p_track_description );
-                var_Change( p_input, psz_variable, VLC_VAR_FREELIST,
-                            &val_list, &text_list);
+                var_FreeList( &val_list, &text_list);
                 vlc_object_release( p_input );
                 libvlc_exception_raise( p_e, "no enough memory" );
                 return NULL;
@@ -1218,7 +1216,7 @@ libvlc_track_description_t *
         p_previous = p_actual;
         p_actual =  NULL;
     }
-    var_Change( p_input, psz_variable, VLC_VAR_FREELIST, &val_list, &text_list);
+    var_FreeList( &val_list, &text_list);
     vlc_object_release( p_input );
 
     return p_track_description;
index f43a815..bece0e4 100644 (file)
@@ -272,7 +272,7 @@ int libvlc_video_get_spu( libvlc_media_player_t *p_mi,
             break;
         }
     }
-    var_Change( p_input_thread, "spu-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );
     return i_spu;
 }
@@ -289,7 +289,7 @@ int libvlc_video_get_spu_count( libvlc_media_player_t *p_mi,
 
     var_Change( p_input_thread, "spu-es", VLC_VAR_GETCHOICES, &val_list, NULL );
     i_spu_count = val_list.p_list->i_count;
-    var_Change( p_input_thread, "spu-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
 
     vlc_object_release( p_input_thread );
     return i_spu_count;
@@ -334,7 +334,7 @@ void libvlc_video_set_spu( libvlc_media_player_t *p_mi, int i_spu,
     }
 
 end:
-    var_Change( p_input_thread, "spu-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );
 }
 
@@ -496,7 +496,7 @@ void libvlc_toggle_teletext( libvlc_media_player_t *p_mi,
             if( list.p_list->i_count > 0 )
                 var_SetInteger( p_input_thread, "spu-es", list.p_list->p_values[0].i_int );
 
-            var_Change( p_input_thread, "teletext-es", VLC_VAR_FREELIST, &list, NULL );
+            var_FreeList( &list, NULL );
         }
     }
     vlc_object_release( p_input_thread );
@@ -514,7 +514,7 @@ int libvlc_video_get_track_count( libvlc_media_player_t *p_mi,
 
     var_Change( p_input_thread, "video-es", VLC_VAR_GETCHOICES, &val_list, NULL );
     i_track_count = val_list.p_list->i_count;
-    var_Change( p_input_thread, "video-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
 
     vlc_object_release( p_input_thread );
     return i_track_count;
@@ -557,7 +557,7 @@ int libvlc_video_get_track( libvlc_media_player_t *p_mi,
             break;
         }
     }
-    var_Change( p_input_thread, "video-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );
     return i_track;
 }
@@ -588,6 +588,6 @@ void libvlc_video_set_track( libvlc_media_player_t *p_mi, int i_track,
     libvlc_exception_raise( p_e, "Video track out of range" );
 
 end:
-    var_Change( p_input_thread, "video-es", VLC_VAR_FREELIST, &val_list, NULL );
+    var_FreeList( &val_list, NULL );
     vlc_object_release( p_input_thread );
 }
index a0b0b1c..655e604 100644 (file)
@@ -1689,7 +1689,7 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
                 break;
             }
         }
-        var_Change( p_sys->p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
+        var_FreeList( &val, NULL );
     }
     else if( p_sys->i_mode == ES_OUT_MODE_AUTO )
     {
index 119b41c..c40b9f0 100644 (file)
@@ -1123,7 +1123,7 @@ static void InitPrograms( input_thread_t * p_input )
             }
             else
             {
-                var_Change( p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
+                var_FreeList( &val, NULL );
             }
         }
     }
@@ -1138,7 +1138,7 @@ static void InitPrograms( input_thread_t * p_input )
     {
         demux_Control( p_input->p->input.p_demux, DEMUX_SET_GROUP, -1,
                         val.p_list );
-        var_Change( p_input, "programs", VLC_VAR_FREELIST, &val, NULL );
+        var_FreeList( &val, NULL );
     }
     else
     {
@@ -3228,7 +3228,7 @@ static void SubtitleAdd( input_thread_t *p_input, char *psz_subtitle, bool b_for
             es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_DEFAULT_BY_ID, i_id );
             es_out_Control( p_input->p->p_es_out_display, ES_OUT_SET_ES_BY_ID, i_id );
         }
-        var_Change( p_input, "spu-es", VLC_VAR_FREELIST, &list, NULL );
+        var_FreeList( &list, NULL );
     }
 }
 
index fc42f05..3f1df05 100644 (file)
@@ -416,6 +416,7 @@ __var_Command
 __var_Create
 __var_DelCallback
 __var_Destroy
+var_FreeList
 __var_Get
 var_GetChecked
 __var_Set
index 52a7f7e..313f700 100644 (file)
@@ -605,20 +605,6 @@ int __var_Change( vlc_object_t *p_this, const char *psz_name,
                 }
             }
             break;
-        case VLC_VAR_FREELIST:
-            FreeList( p_val );
-            if( p_val2 && p_val2->p_list )
-            {
-                for( i = 0; i < p_val2->p_list->i_count; i++ )
-                    free( p_val2->p_list->p_values[i].psz_string );
-                if( p_val2->p_list->i_count )
-                {
-                    free( p_val2->p_list->p_values );
-                    free( p_val2->p_list->pi_types );
-                }
-                free( p_val2->p_list );
-            }
-            break;
         case VLC_VAR_SETTEXT:
             free( p_var->psz_text );
             if( p_val && p_val->psz_string )
@@ -1535,3 +1521,25 @@ int __var_Command( vlc_object_t *p_this, const char *psz_name,
 
     return i_ret;
 }
+
+
+/**
+ * Free a list and the associated strings
+ * @param p_val: the list variable
+ * @param p_val2: the variable associated or NULL
+ */
+void var_FreeList( vlc_value_t *p_val, vlc_value_t *p_val2 )
+{
+    FreeList( p_val );
+    if( p_val2 && p_val2->p_list )
+    {
+        for( int i = 0; i < p_val2->p_list->i_count; i++ )
+            free( p_val2->p_list->p_values[i].psz_string );
+        if( p_val2->p_list->i_count )
+        {
+            free( p_val2->p_list->p_values );
+            free( p_val2->p_list->pi_types );
+        }
+        free( p_val2->p_list );
+    }
+}