]> git.sesse.net Git - vlc/blobdiff - modules/audio_output/auhal.c
Check asprintf return value and avoid one unneeded strdup.
[vlc] / modules / audio_output / auhal.c
index 06783b8e6ed63506621bbcd80e2bbdc0b72f98d2..d4235a2100e6b0db6a5d715b9a46ceb470ce8b82 100644 (file)
@@ -30,7 +30,8 @@
 
 #include <unistd.h>
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_plugin.h>
 #include <vlc_interface.h>
 #include <vlc_aout.h>
 
@@ -134,7 +135,7 @@ static int      AudioDeviceCallback     ( vlc_object_t *, const char *,
 
 vlc_module_begin();
     set_shortname( "auhal" );
-    set_description( _("HAL AudioUnit output") );
+    set_description( N_("HAL AudioUnit output") );
     set_capability( "audio output", 101 );
     set_category( CAT_AUDIO );
     set_subcategory( SUBCAT_AUDIO_AOUT );
@@ -160,10 +161,7 @@ static int Open( vlc_object_t * p_this )
     /* Allocate structure */
     p_aout->output.p_sys = malloc( sizeof( aout_sys_t ) );
     if( p_aout->output.p_sys == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
-        return( VLC_ENOMEM );
-    }
+        return VLC_ENOMEM;
 
     p_sys = p_aout->output.p_sys;
     p_sys->i_default_dev = 0;
@@ -648,10 +646,7 @@ static int OpenSPDIF( aout_instance_t * p_aout )
     i_streams = i_param_size / sizeof( AudioStreamID );
     p_streams = (AudioStreamID *)malloc( i_param_size );
     if( p_streams == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
         return false;
-    }
  
     err = AudioDeviceGetProperty( p_sys->i_selected_dev, 0, FALSE,
                                     kAudioDevicePropertyStreams,
@@ -684,10 +679,7 @@ static int OpenSPDIF( aout_instance_t * p_aout )
         i_formats = i_param_size / sizeof( AudioStreamBasicDescription );
         p_format_list = (AudioStreamBasicDescription *)malloc( i_param_size );
         if( p_format_list == NULL )
-        {
-            msg_Err( p_aout, "could not malloc the memory" );
             continue;
-        }
  
         err = AudioStreamGetProperty( p_streams[i], 0,
                                           kAudioStreamPropertyPhysicalFormats,
@@ -950,10 +942,7 @@ static void Probe( aout_instance_t * p_aout )
     /* Allocate DeviceID array */
     p_devices = (AudioDeviceID*)malloc( sizeof(AudioDeviceID) * p_sys->i_devices );
     if( p_devices == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
         goto error;
-    }
 
     /* Populate DeviceID array */
     err = AudioHardwareGetProperty( kAudioHardwarePropertyDevices,
@@ -976,7 +965,7 @@ static void Probe( aout_instance_t * p_aout )
     p_sys->i_default_dev = devid_def;
  
     var_Create( p_aout, "audio-device", VLC_VAR_INTEGER|VLC_VAR_HASCHOICE );
-    text.psz_string = _("Audio Device");
+    text.psz_string = (char*)_("Audio Device");
     var_Change( p_aout, "audio-device", VLC_VAR_SETTEXT, &text, NULL );
  
     for( i = 0; i < p_sys->i_devices; i++ )
@@ -1009,8 +998,9 @@ static void Probe( aout_instance_t * p_aout )
 
         /* Add the menu entries */
         val.i_int = (int)p_devices[i];
-        text.psz_string = strdup( psz_name );
+        text.psz_string = psz_name;
         var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text );
+        text.psz_string = NULL;
         if( p_sys->i_default_dev == p_devices[i] )
         {
             /* The default device is the selected device normally */
@@ -1021,14 +1011,17 @@ static void Probe( aout_instance_t * p_aout )
         if( AudioDeviceSupportsDigital( p_aout, p_devices[i] ) )
         {
             val.i_int = (int)p_devices[i] | AOUT_VAR_SPDIF_FLAG;
-            asprintf( &text.psz_string, _("%s (Encoded Output)"), psz_name );
-            var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text );
-            if( p_sys->i_default_dev == p_devices[i] && config_GetInt( p_aout, "spdif" ) )
+            if( asprintf( &text.psz_string, _("%s (Encoded Output)"), psz_name ) != -1 )
             {
-                /* We selected to prefer SPDIF output if available
-                 * then this "dummy" entry should be selected */
-                var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL );
-                var_Set( p_aout, "audio-device", val );
+                var_Change( p_aout, "audio-device", VLC_VAR_ADDCHOICE, &val, &text );
+                free( text.psz_string );
+                if( p_sys->i_default_dev == p_devices[i] && config_GetInt( p_aout, "spdif" ) )
+                {
+                    /* We selected to prefer SPDIF output if available
+                     * then this "dummy" entry should be selected */
+                    var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL );
+                    var_Set( p_aout, "audio-device", val );
+                }
             }
         }
  
@@ -1100,10 +1093,7 @@ static int AudioDeviceSupportsDigital( aout_instance_t *p_aout, AudioDeviceID i_
     i_streams = i_param_size / sizeof( AudioStreamID );
     p_streams = (AudioStreamID *)malloc( i_param_size );
     if( p_streams == NULL )
-    {
-        msg_Err( p_aout, "out of memory" );
         return VLC_ENOMEM;
-    }
  
     err = AudioDeviceGetProperty( i_dev_id, 0, FALSE,
                                     kAudioDevicePropertyStreams,
@@ -1149,10 +1139,7 @@ static int AudioStreamSupportsDigital( aout_instance_t *p_aout, AudioStreamID i_
     i_formats = i_param_size / sizeof( AudioStreamBasicDescription );
     p_format_list = (AudioStreamBasicDescription *)malloc( i_param_size );
     if( p_format_list == NULL )
-    {
-        msg_Err( p_aout, "could not malloc the memory" );
         return false;
-    }
  
     err = AudioStreamGetProperty( i_stream_id, 0,
                                       kAudioStreamPropertyPhysicalFormats,