OSDN Git Service

Fix about 156,199 bytes of leaked memory.
authorsaintdev <saintdev@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 31 Mar 2007 06:55:02 +0000 (06:55 +0000)
committersaintdev <saintdev@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Sat, 31 Mar 2007 06:55:02 +0000 (06:55 +0000)
git-svn-id: svn://localhost/HandBrake/trunk@469 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.c
libhb/deca52.c
libhb/encavcodec.c
libhb/encfaac.c
libhb/encx264.c
libhb/hb.c
libhb/reader.c
libhb/render.c
libhb/scan.c
libhb/sync.c
libhb/work.c

index 1d66e0b..560a839 100644 (file)
@@ -515,11 +515,30 @@ hb_title_t * hb_title_init( char * dvd, int index )
 void hb_title_close( hb_title_t ** _t )
 {
     hb_title_t * t = *_t;
+    hb_audio_t * audio;
+    hb_chapter_t * chapter;
+    hb_subtitle_t * subtitle;
 
+    while( ( audio = hb_list_item( t->list_audio, 0 ) ) )
+    {
+        hb_list_rem( t->list_audio, audio );
+        free( audio );
+    }
     hb_list_close( &t->list_audio );
+    
+    while( ( chapter = hb_list_item( t->list_chapter, 0 ) ) )
+    {
+        hb_list_rem( t->list_chapter, chapter );
+        free( chapter );
+    }
     hb_list_close( &t->list_chapter );
+    
+    while( ( subtitle = hb_list_item( t->list_subtitle, 0 ) ) )
+    {
+        hb_list_rem( t->list_subtitle, subtitle );
+        free( subtitle );
+    }
     hb_list_close( &t->list_subtitle );
-    free( t->job );
 
     free( t );
     *_t = NULL;
index a5f3123..0664584 100644 (file)
@@ -105,6 +105,9 @@ void deca52Close( hb_work_object_t * w )
 {
     hb_work_private_t * pv = w->private_data;
     a52_free( pv->state );
+    hb_list_empty( &pv->list );
+    free( pv );
+    w->private_data = NULL;
 }
 
 /***********************************************************************
index c71c838..721644f 100644 (file)
@@ -151,12 +151,16 @@ void encavcodecClose( hb_work_object_t * w )
     if( pv->context )
     {
         hb_log( "encavcodec: closing libavcodec" );
+        avcodec_flush_buffers( pv->context );
         avcodec_close( pv->context );
+        free( pv->context );
     }
     if( pv->file )
     {
         fclose( pv->file );
     }
+    free( pv );
+    w->private_data = NULL;
 }
 
 /***********************************************************************
index 5eee395..7ed9853 100644 (file)
@@ -122,6 +122,8 @@ void encfaacClose( hb_work_object_t * w )
     faacEncClose( pv->faac );
     free( pv->buf );
     hb_list_empty( &pv->list );
+    free( pv );
+    w->private_data = NULL;
 }
 
 /***********************************************************************
index 747bae9..b48bfda 100644 (file)
@@ -28,7 +28,6 @@ struct hb_work_private_s
     hb_job_t       * job;
     x264_t         * x264;
     x264_picture_t   pic_in;
-    x264_picture_t   pic_out;
 
     char             filename[1024];
 };
@@ -215,7 +214,10 @@ int encx264Init( hb_work_object_t * w, hb_job_t * job )
 void encx264Close( hb_work_object_t * w )
 {
     hb_work_private_t * pv = w->private_data;
+    x264_picture_clean( &pv->pic_in );
     x264_encoder_close( pv->x264 );
+    free( pv );
+    w->private_data = NULL;
 
     /* TODO */
 }
@@ -226,6 +228,7 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
     hb_work_private_t * pv = w->private_data;
     hb_job_t    * job = pv->job;
     hb_buffer_t * in = *buf_in, * buf;
+    x264_picture_t   pic_out;
     int           i_nal;
     x264_nal_t  * nal;
     int i;
@@ -253,7 +256,7 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
     pv->pic_in.i_pts = in->start;
 
     x264_encoder_encode( pv->x264, &nal, &i_nal,
-                         &pv->pic_in, &pv->pic_out );
+                         &pv->pic_in, &pic_out );
 
     /* Should be way too large */
     buf        = hb_buffer_init( 3 * job->width * job->height / 2 );
@@ -300,12 +303,12 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
 
         /* For IDR (key frames), buf->key = 1,
            and the same for regular I-frames. */
-        if( (pv->pic_out.i_type == X264_TYPE_IDR) || (pv->pic_out.i_type == X264_TYPE_I) )
+        if( (pic_out.i_type == X264_TYPE_IDR) || (pic_out.i_type == X264_TYPE_I) )
         {
         buf->key = 1;
         }
         /* For B-frames, buf->key = 2 */
-        else if( (pv->pic_out.i_type == X264_TYPE_B) )
+        else if( (pic_out.i_type == X264_TYPE_B) )
         {
         buf->key = 2;
         }                
@@ -313,7 +316,7 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
            However, it doesn't seem to ever be used...
            They just show up as buf->key == 2 like
            regular b-frames. */
-        else if( (pv->pic_out.i_type == X264_TYPE_BREF) )
+        else if( (pic_out.i_type == X264_TYPE_BREF) )
         {
             buf->key = 3;
         }
@@ -326,7 +329,7 @@ int encx264Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
         /* Store the output presentation time stamp
            from x264 for use by muxmp4 in off-setting
            b-frames with the CTTS atom. */
-        buf->encodedPTS = pv->pic_out.i_pts;
+        buf->encodedPTS = pic_out.i_pts;
 
                 buf->size += size;
         }
index c1748e8..d1eac13 100644 (file)
@@ -556,6 +556,7 @@ void hb_add( hb_handle_t * h, hb_job_t * job )
     /* Copy the job */
     job_copy        = calloc( sizeof( hb_job_t ), 1 );
     memcpy( job_copy, job, sizeof( hb_job_t ) );
+    title_copy->job = job_copy;
     job_copy->title = title_copy;
     job_copy->file  = strdup( job->file );
     job_copy->h     = h;
@@ -680,6 +681,7 @@ void hb_close( hb_handle_t ** _h )
     while( ( title = hb_list_item( h->list_title, 0 ) ) )
     {
         hb_list_rem( h->list_title, title );
+        free( title->job );
         hb_title_close( &title );
     }
     hb_list_close( &h->list_title );
index 47ec9d5..35939f9 100644 (file)
@@ -115,6 +115,8 @@ static void ReaderFunc( void * _r )
     hb_buffer_close( &r->ps );
     hb_dvd_stop( r->dvd );
     hb_dvd_close( &r->dvd );
+    free( r );
+    _r = NULL;
 
     hb_log( "reader: done" );
 }
index cf6d7b3..1700470 100644 (file)
@@ -151,6 +151,11 @@ int renderWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
 
 void renderClose( hb_work_object_t * w )
 {
+    hb_work_private_t * pv = w->private_data;
+    
+    img_resample_close( pv->context );
+    free( pv );
+    w->private_data = NULL;
 }
 
 int renderInit( hb_work_object_t * w, hb_job_t * job )
index 5d817c7..e969a43 100644 (file)
@@ -114,7 +114,7 @@ static void ScanFunc( void * _data )
             hb_log( "scan: title %d is duplicate with title %d",
                     title->index, title_tmp->index );
             hb_list_rem( data->list_title, title );
-            free( title );
+            free( title );      /* This _will_ leak! */
             continue;
         }
 
@@ -225,6 +225,9 @@ static void ScanFunc( void * _data )
     {
         hb_dvd_close( &data->dvd );
     }
+    free( data->path );
+    free( data );
+    _data = NULL;
 }
 
 /***********************************************************************
index 22266ec..b8f49fd 100644 (file)
@@ -135,6 +135,9 @@ void syncClose( hb_work_object_t * w )
             src_delete( pv->sync_audio[i].state );
         }
     }
+    
+    free( pv );
+    w->private_data = NULL;
 }
 
 /***********************************************************************
index 97c332b..3c1cead 100644 (file)
@@ -369,6 +369,8 @@ static void do_job( hb_job_t * job, int cpu_count )
             w = NULL;
         }
     }
+    
+    hb_list_close( &job->list_work );
 
     /* Stop read & write threads */
     hb_thread_close( &job->reader );
@@ -393,6 +395,9 @@ static void do_job( hb_job_t * job, int cpu_count )
         hb_fifo_close( &audio->fifo_sync );
         hb_fifo_close( &audio->fifo_out );
     }
+    
+    hb_title_close( &job->title );
+    free( job );
 }
 
 /**