--- vlc-0.8.6.h.orig/modules/audio_output/esd.c
+++ vlc-0.8.6.h/modules/audio_output/esd.c
@@ -130,18 +130,13 @@
     /* Open a socket for playing a stream
      * and try to open /dev/dsp if there's no EsounD */
     psz_server = config_GetPsz( p_aout, "esdserver" );
-    if( psz_server && *psz_server )
-    {
-        p_sys->i_fd = esd_play_stream_fallback( p_sys->esd_format,
-                                                p_aout->output.output.i_rate,
-                                                psz_server, "vlc" );
-    }
-    else
-    {
-        p_sys->i_fd = esd_play_stream_fallback( p_sys->esd_format,
-                                                p_aout->output.output.i_rate,
-                                                NULL, "vlc" );
-    }
+    if( psz_server && !*psz_server )
+        psz_server = NULL; /* empty string is as good as NULL */
+    if( psz_server )
+        msg_Dbg( p_aout, "using esd server %s", psz_server );
+    p_sys->i_fd = esd_play_stream_fallback( p_sys->esd_format,
+                                            p_aout->output.output.i_rate,
+                                            psz_server, "vlc" );
 
     if( p_sys->i_fd < 0 )
     {
@@ -151,18 +146,20 @@
         return VLC_EGENERIC;
     }
 
-    if( psz_server && *psz_server )
+    i_newfd = esd_open_sound( psz_server );
+    if( psz_server )
     {
         struct timeval start, stop;
         esd_server_info_t * p_info;
 
         gettimeofday( &start, NULL );
-        p_info = esd_get_server_info( p_sys->i_fd );
+        p_info = esd_get_server_info( i_newfd );
         gettimeofday( &stop, NULL );
 
         p_sys->latency = (mtime_t)( stop.tv_sec - start.tv_sec )
                            * (mtime_t)1000000;
         p_sys->latency += stop.tv_usec - start.tv_usec;
+	esd_free_server_info(p_info);
     }
     else
     {
@@ -172,7 +169,7 @@
     /* ESD latency is calculated for 44100 Hz. We don't have any way to get the
      * number of buffered samples, so I assume ESD_BUF_SIZE/2 */
     p_sys->latency +=
-        (mtime_t)( esd_get_latency( i_newfd = esd_open_sound(NULL) )
+        (mtime_t)( esd_get_latency( i_newfd )
                     + ESD_BUF_SIZE / 2
                       * p_aout->output.output.i_bytes_per_frame
                       * p_aout->output.output.i_rate
@@ -181,7 +178,7 @@
       / p_aout->output.output.i_bytes_per_frame
       / p_aout->output.output.i_rate;
 
-    close( i_newfd );
+    esd_close( i_newfd );
     return VLC_SUCCESS;
 }
 

