]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/osdmenu.c
Fix memleak.
[vlc] / modules / video_filter / osdmenu.c
index 0e0b9d40849afe4ee5e80548fa5146af4b22001b..8a492046d74685a09d2da76824d0b3f7f421c81d 100644 (file)
@@ -28,7 +28,7 @@
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_vout.h>
 #include <vlc_filter.h>
@@ -80,8 +80,8 @@
     "means less transparency. The default is being not transparent " \
     "(value 255) the minimum is fully transparent (value 0)." )
 
-static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
-static const char *ppsz_pos_descriptions[] =
+static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
+static const char *const ppsz_pos_descriptions[] =
 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
   N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
 
@@ -184,10 +184,7 @@ static int CreateFilter ( vlc_object_t *p_this )
 
     p_filter->p_sys = p_sys = (filter_sys_t *) malloc( sizeof(filter_sys_t) );
     if( !p_filter->p_sys )
-    {
-        msg_Err( p_filter, "out of memory" );
         return VLC_ENOMEM;
-    }
     memset( p_sys, 0, sizeof(filter_sys_t) );
 
     /* Populating struct */
@@ -231,18 +228,11 @@ static int CreateFilter ( vlc_object_t *p_this )
         p_sys->p_menu->i_x = 0;
         p_sys->p_menu->i_y = 0;
     }
-    else if( (p_sys->i_x >= 0) || (p_sys->i_y >= 0) )
+    else
     {
         p_sys->p_menu->i_x = p_sys->i_x;
         p_sys->p_menu->i_y = p_sys->i_y;
     }
-    else if( (p_sys->p_menu->i_x < 0) ||
-             (p_sys->p_menu->i_y < 0) )
-    {
-        p_sys->b_absolute = false;
-        p_sys->p_menu->i_x = 0;
-        p_sys->p_menu->i_y = 0;
-    }
 
     /* Set up p_filter */
     p_sys->i_last_date = mdate();
@@ -282,6 +272,7 @@ error:
 
     osd_MenuDelete( p_this, p_sys->p_menu );
     p_sys->p_menu = NULL;
+    free( p_sys->psz_path );
     free( p_sys->psz_file );
     free( p_sys );
     return VLC_EGENERIC;
@@ -300,12 +291,15 @@ static void DestroyFilter( vlc_object_t *p_this )
     var_DelCallback( p_filter, OSD_CFG "update", OSDMenuCallback, p_sys );
     var_DelCallback( p_filter, OSD_CFG "alpha", OSDMenuCallback, p_sys );
 
-    var_DelCallback( p_sys->p_menu, "osd-menu-update",
-                     OSDMenuUpdateEvent, p_filter );
-    var_DelCallback( p_sys->p_menu, "osd-menu-visible",
-                     OSDMenuVisibleEvent, p_filter );
+    if( p_sys )
+    {
+        var_DelCallback( p_sys->p_menu, "osd-menu-update",
+                         OSDMenuUpdateEvent, p_filter );
+        var_DelCallback( p_sys->p_menu, "osd-menu-visible",
+                         OSDMenuVisibleEvent, p_filter );
+    }
 
-    if( p_sys->p_vout )
+    if( p_sys && p_sys->p_vout )
     {
         var_DelCallback( p_sys->p_vout, "mouse-x",
                         MouseEvent, p_sys );
@@ -327,10 +321,14 @@ static void DestroyFilter( vlc_object_t *p_this )
     var_Destroy( p_this, OSD_CFG "update" );
     var_Destroy( p_this, OSD_CFG "alpha" );
 
-    osd_MenuDelete( p_filter, p_sys->p_menu );
+    if( p_sys )
+    {
+        osd_MenuDelete( p_filter, p_sys->p_menu );
 
-    free( p_sys->psz_file );
-    free( p_sys );
+        free( p_sys->psz_path );
+        free( p_sys->psz_file );
+        free( p_sys );
+    }
 }
 
 /*****************************************************************************
@@ -466,8 +464,9 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t i_date )
         return NULL; /* we are too early, so wait */
 
     /* Allocate the subpicture internal data. */
-    p_spu = p_filter->pf_sub_buffer_new( p_filter );
-    if( !p_spu ) return NULL;
+    p_spu = filter_NewSubpicture( p_filter );
+    if( !p_spu )
+        return NULL;
 
     p_spu->b_ephemer = true;
     p_spu->b_fade = true;