Commit 33d697de authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

control/media_descriptor.c: Use vlc_gc_* function to prevent input_item_t...

control/media_descriptor.c: Use vlc_gc_* function to prevent input_item_t leak. And prefer p_md over p_media_desc as a variable name. 
parent bdf7bd5e
...@@ -31,14 +31,14 @@ ...@@ -31,14 +31,14 @@
/************************************************************************** /**************************************************************************
* Preparse if not already done (Private) * Preparse if not already done (Private)
**************************************************************************/ **************************************************************************/
static void preparse_if_needed( libvlc_media_descriptor_t *p_media_desc ) static void preparse_if_needed( libvlc_media_descriptor_t *p_md )
{ {
/* XXX: need some locking here */ /* XXX: need some locking here */
if (!p_media_desc->b_preparsed) if (!p_md->b_preparsed)
{ {
input_Preparse( p_media_desc->p_libvlc_instance->p_libvlc_int, input_Preparse( p_md->p_libvlc_instance->p_libvlc_int,
p_media_desc->p_input_item ); p_md->p_input_item );
p_media_desc->b_preparsed = VLC_TRUE; p_md->b_preparsed = VLC_TRUE;
} }
} }
...@@ -51,7 +51,7 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new( ...@@ -51,7 +51,7 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new(
libvlc_exception_t *p_e ) libvlc_exception_t *p_e )
{ {
input_item_t * p_input_item; input_item_t * p_input_item;
libvlc_media_descriptor_t * p_media_desc; libvlc_media_descriptor_t * p_md;
p_input_item = input_ItemNew( p_instance->p_libvlc_int, psz_mrl, psz_mrl ); p_input_item = input_ItemNew( p_instance->p_libvlc_int, psz_mrl, psz_mrl );
...@@ -61,12 +61,14 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new( ...@@ -61,12 +61,14 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new(
return NULL; return NULL;
} }
p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) ); p_md = malloc( sizeof(libvlc_media_descriptor_t) );
p_media_desc->p_libvlc_instance = p_instance; p_md->p_libvlc_instance = p_instance;
p_media_desc->p_input_item = p_input_item; p_md->p_input_item = p_input_item;
p_media_desc->b_preparsed = VLC_FALSE; p_md->b_preparsed = VLC_FALSE;
vlc_gc_incref( p_md->p_input_item );
return p_media_desc; return p_md;
} }
/************************************************************************** /**************************************************************************
...@@ -78,7 +80,7 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item( ...@@ -78,7 +80,7 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
input_item_t *p_input_item, input_item_t *p_input_item,
libvlc_exception_t *p_e ) libvlc_exception_t *p_e )
{ {
libvlc_media_descriptor_t * p_media_desc; libvlc_media_descriptor_t * p_md;
if (!p_input_item) if (!p_input_item)
{ {
...@@ -86,12 +88,14 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item( ...@@ -86,12 +88,14 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
return NULL; return NULL;
} }
p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) ); p_md = malloc( sizeof(libvlc_media_descriptor_t) );
p_media_desc->p_libvlc_instance = p_instance; p_md->p_libvlc_instance = p_instance;
p_media_desc->p_input_item = p_input_item; p_md->p_input_item = p_input_item;
p_media_desc->b_preparsed = VLC_TRUE; p_md->b_preparsed = VLC_TRUE;
vlc_gc_incref( p_md->p_input_item );
return p_media_desc; return p_md;
} }
/************************************************************************** /**************************************************************************
...@@ -103,11 +107,8 @@ void libvlc_media_descriptor_destroy( libvlc_media_descriptor_t *p_md ) ...@@ -103,11 +107,8 @@ void libvlc_media_descriptor_destroy( libvlc_media_descriptor_t *p_md )
return; return;
/* XXX: locking */ /* XXX: locking */
vlc_gc_decref( p_md->p_input_item );
/* XXX: here we don't clean the item, because we can't properly track
* if it is needed by some other object. This is a leak(!). */
/* input_ItemClean( p_md->p_input_item ); */
free( p_md ); free( p_md );
} }
...@@ -122,6 +123,8 @@ libvlc_media_descriptor_duplicate( libvlc_media_descriptor_t *p_md_orig ) ...@@ -122,6 +123,8 @@ libvlc_media_descriptor_duplicate( libvlc_media_descriptor_t *p_md_orig )
p_md = malloc( sizeof(libvlc_media_descriptor_t) ); p_md = malloc( sizeof(libvlc_media_descriptor_t) );
memcpy( p_md, p_md_orig, sizeof(libvlc_media_descriptor_t) ); memcpy( p_md, p_md_orig, sizeof(libvlc_media_descriptor_t) );
vlc_gc_incref( p_md->p_input_item );
return p_md; return p_md;
} }
...@@ -134,7 +137,7 @@ static const int meta_conversion[] = ...@@ -134,7 +137,7 @@ static const int meta_conversion[] =
[libvlc_meta_Artist] = 1 [libvlc_meta_Artist] = 1
}; };
char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_meta_desc, char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_md,
libvlc_meta_t e_meta, libvlc_meta_t e_meta,
libvlc_exception_t *p_e ) libvlc_exception_t *p_e )
{ {
...@@ -143,9 +146,9 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_meta_desc, ...@@ -143,9 +146,9 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_meta_desc,
/* XXX: locking */ /* XXX: locking */
preparse_if_needed( p_meta_desc ); preparse_if_needed( p_md );
ppsz_meta = (char**)p_meta_desc->p_input_item->p_meta; ppsz_meta = (char**)p_md->p_input_item->p_meta;
ppz_meta = ppsz_meta[ meta_conversion[e_meta] ]; ppz_meta = ppsz_meta[ meta_conversion[e_meta] ];
if( !ppz_meta ) if( !ppz_meta )
...@@ -153,3 +156,4 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_meta_desc, ...@@ -153,3 +156,4 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_meta_desc,
return strdup( ppz_meta ); return strdup( ppz_meta );
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment