control/media_descriptor.c: Make sure we don't strdup a NULL ptr.
[vlc.git] / src / control / media_descriptor.c
index ecd3c52..d5c076e 100644 (file)
@@ -56,7 +56,10 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new(
     p_input_item = input_ItemNew( p_instance->p_libvlc_int, psz_mrl, psz_mrl );
 
     if (!p_input_item)
-        return NULL; /* XXX: throw an exception */
+    {
+        libvlc_exception_raise( p_e, "Can't create md's input_item" );
+        return NULL;
+    }
 
     p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) );
     p_media_desc->p_libvlc_instance = p_instance;
@@ -72,12 +75,16 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new(
  **************************************************************************/
 libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
                                    libvlc_instance_t *p_instance,
-                                   input_item_t *p_input_item )
+                                   input_item_t *p_input_item,
+                                   libvlc_exception_t *p_e )
 {
     libvlc_media_descriptor_t * p_media_desc;
 
     if (!p_input_item)
-        return NULL; /* XXX: throw an exception */
+    {
+        libvlc_exception_raise( p_e, "No input item given" );
+        return NULL;
+    }
 
     p_media_desc = malloc( sizeof(libvlc_media_descriptor_t) );
     p_media_desc->p_libvlc_instance = p_instance;
@@ -129,12 +136,17 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_meta_desc,
                                          libvlc_exception_t *p_e )
 {
     char ** ppsz_meta;
+    char *ppz_meta;
 
     /* XXX: locking */
 
     preparse_if_needed( p_meta_desc );
 
     ppsz_meta = (char**)p_meta_desc->p_input_item->p_meta;
+    ppz_meta = ppsz_meta[ meta_conversion[e_meta] ];
+
+    if( !ppz_meta )
+        return NULL;
 
-    return strdup( ppsz_meta[ meta_conversion[e_meta] ] );
+    return strdup( ppz_meta );
 }