[vlc-devel] commit: Don't leak memory when something goes wrong. ( Rémi Duraffort )

git version control git at videolan.org
Wed Jul 9 23:44:24 CEST 2008


vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Wed Jul  9 23:31:32 2008 +0200| [5f2b369ce56dd68a3278022bdc3e97518d140a7e]

Don't leak memory when something goes wrong.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5f2b369ce56dd68a3278022bdc3e97518d140a7e
---

 modules/access/jack.c |   32 +++++++++++++++++++-------------
 1 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/modules/access/jack.c b/modules/access/jack.c
index b71745b..ba8804f 100644
--- a/modules/access/jack.c
+++ b/modules/access/jack.c
@@ -143,10 +143,7 @@ static int Open( vlc_object_t *p_this )
     /* Allocate structure */
     p_demux->p_sys = p_sys = calloc( 1, sizeof( demux_sys_t ) );
     if( p_sys == NULL )
-    {
-        msg_Err( p_demux, "out of memory, cannot allocate structure" );
         return VLC_ENOMEM;
-    }
     memset( p_sys, 0, sizeof( demux_sys_t ) );
 
     /* Parse MRL */
@@ -188,7 +185,8 @@ static int Open( vlc_object_t *p_this )
         p_sys->i_channels * sizeof( jack_port_t* ) );
     if( p_sys->pp_jack_port_input == NULL )
     {
-        msg_Err( p_demux, "out of memory, cannot allocate input ports" );
+        jack_client_close( p_sys->p_jack_client );
+        free( p_sys );
         return VLC_ENOMEM;
     }
 
@@ -200,7 +198,9 @@ static int Open( vlc_object_t *p_this )
          * sizeof( jack_default_audio_sample_t ) );
     if( p_sys->p_jack_ringbuffer == NULL )
     {
-        msg_Err( p_demux, "out of memory, cannot allocate ringbuffer" );
+        free( p_sys->pp_jack_port_input );
+        jack_client_close( p_sys->p_jack_client );
+        free( p_sys );
         return VLC_ENOMEM;
     }
 
@@ -215,10 +215,9 @@ static int Open( vlc_object_t *p_this )
         if( p_sys->pp_jack_port_input[i] == NULL )
         {
             msg_Err( p_demux, "failed to register a JACK port" );
-            if( p_sys->p_jack_client) jack_client_close( p_sys->p_jack_client );
+            jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
             free( p_sys->pp_jack_port_input );
-            if( p_sys->p_jack_ringbuffer ) jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
-            free( p_sys->pp_jack_buffer );
+            jack_client_close( p_sys->p_jack_client );
             free( p_sys );
             return VLC_EGENERIC;
         }
@@ -229,7 +228,12 @@ static int Open( vlc_object_t *p_this )
         * sizeof( jack_default_audio_sample_t * ) );
     if( p_sys->pp_jack_buffer == NULL )
     {
-        msg_Err( p_demux, "out of memory, cannot allocate input buffer" );
+        for( i = 0; i < p_sys->i_channels; i++ )
+            jack_port_unregister( p_sys->p_jack_client, p_sys->pp_jack_port_input[i] );
+        jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
+        free( p_sys->pp_jack_port_input );
+        jack_client_close( p_sys->p_jack_client );
+        free( p_sys );
         return VLC_ENOMEM;
     }
 
@@ -240,10 +244,12 @@ static int Open( vlc_object_t *p_this )
     if ( jack_activate( p_sys->p_jack_client ) )
     {
         msg_Err( p_demux, "failed to activate JACK client" );
-        if( p_sys->p_jack_client) jack_client_close( p_sys->p_jack_client );
-        free( p_sys->pp_jack_port_input );
-        if( p_sys->p_jack_ringbuffer ) jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
         free( p_sys->pp_jack_buffer );
+        for( i = 0; i < p_sys->i_channels; i++ )
+            jack_port_unregister( p_sys->p_jack_client, p_sys->pp_jack_port_input[i] );
+        jack_ringbuffer_free( p_sys->p_jack_ringbuffer );
+        free( p_sys->pp_jack_port_input );
+        jack_client_close( p_sys->p_jack_client );
         free( p_sys );
         return VLC_EGENERIC;
     }
@@ -288,7 +294,7 @@ static int Open( vlc_object_t *p_this )
                     jack_port_name( p_sys->pp_jack_port_input[i_input_ports] ) );
             }
         }
-    free( pp_jack_port_output );
+        free( pp_jack_port_output );
     }
 
     /* info about jack server */




More information about the vlc-devel mailing list