From 0d351ab03f9b0f753a7e7c9878963a366663f129 Mon Sep 17 00:00:00 2001 From: Ewald Snel Date: Sun, 2 Feb 2003 11:21:34 +0000 Subject: Fix memory leak in XShm driver CVS patchset: 4085 CVS date: 2003/02/02 11:21:34 --- src/video_out/video_out_xshm.c | 9 ++++++++- src/video_out/yuv2rgb.c | 24 +++++++++++++++++++++++- src/video_out/yuv2rgb.h | 13 ++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/video_out/video_out_xshm.c b/src/video_out/video_out_xshm.c index 116c52b7b..30cf25c9c 100644 --- a/src/video_out/video_out_xshm.c +++ b/src/video_out/video_out_xshm.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: video_out_xshm.c,v 1.101 2003/01/24 17:04:37 esnel Exp $ + * $Id: video_out_xshm.c,v 1.102 2003/02/02 11:21:34 esnel Exp $ * * video_out_xshm.c, X11 shared memory extension interface for xine * @@ -359,6 +359,11 @@ static void xshm_frame_dispose (vo_frame_t *vo_img) { XUnlockDisplay (this->display); } + frame->yuv2rgb->dispose (frame->yuv2rgb); + + free (frame->chunk[0]); + free (frame->chunk[1]); + free (frame->chunk[2]); free (frame); } @@ -954,6 +959,8 @@ static void xshm_dispose (vo_driver_t *this_gen) { if (this->cur_frame) this->cur_frame->vo_frame.dispose (&this->cur_frame->vo_frame); + this->yuv2rgb_factory->dispose (this->yuv2rgb_factory); + free (this); } diff --git a/src/video_out/yuv2rgb.c b/src/video_out/yuv2rgb.c index b728c809c..74b75d095 100644 --- a/src/video_out/yuv2rgb.c +++ b/src/video_out/yuv2rgb.c @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: yuv2rgb.c,v 1.36 2003/01/25 12:46:10 esnel Exp $ + * $Id: yuv2rgb.c,v 1.37 2003/02/02 11:21:35 esnel Exp $ */ #include "config.h" @@ -94,6 +94,14 @@ static int yuv2rgb_next_slice (yuv2rgb_t *this, uint8_t **dest) { } } +static void yuv2rgb_dispose (yuv2rgb_t *this) { + + free (this->y_chunk); + free (this->u_chunk); + free (this->v_chunk); + free (this); +} + static int yuv2rgb_configure (yuv2rgb_t *this, int source_width, int source_height, int y_stride, int uv_stride, @@ -2235,6 +2243,7 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped case MODE_32_RGB: case MODE_32_BGR: table_32 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t)); + this->table_base = table_32; entry_size = sizeof (uint32_t); table_r = table_32 + 197; @@ -2264,6 +2273,7 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped case MODE_24_RGB: case MODE_24_BGR: table_8 = malloc ((256 + 2*232) * sizeof (uint8_t)); + this->table_base = table_8; entry_size = sizeof (uint8_t); table_r = table_g = table_b = table_8 + 232; @@ -2277,6 +2287,7 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped case MODE_15_RGB: case MODE_16_RGB: table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); + this->table_base = table_16; entry_size = sizeof (uint16_t); table_r = table_16 + 197; @@ -2317,6 +2328,7 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped case MODE_8_RGB: case MODE_8_BGR: table_8 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t)); + this->table_base = table_8; entry_size = sizeof (uint8_t); table_r = table_8 + 197; @@ -2341,6 +2353,7 @@ static void yuv2rgb_setup_tables (yuv2rgb_factory_t *this, int mode, int swapped case MODE_PALETTE: table_16 = malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t)); + this->table_base = table_16; entry_size = sizeof (uint16_t); table_r = table_16 + 197; @@ -3104,6 +3117,7 @@ yuv2rgb_t *yuv2rgb_create_converter (yuv2rgb_factory_t *factory) { this->configure = yuv2rgb_configure; this->next_slice = yuv2rgb_next_slice; + this->dispose = yuv2rgb_dispose; return this; } @@ -3131,6 +3145,12 @@ int yuv2rgb_get_gamma (yuv2rgb_factory_t *this) { return this->gamma; } +static void yuv2rgb_factory_dispose (yuv2rgb_factory_t *this) { + + free (this->table_base); + free (this); +} + yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped, uint8_t *cmap) { @@ -3148,7 +3168,9 @@ yuv2rgb_factory_t* yuv2rgb_factory_init (int mode, int swapped, this->create_converter = yuv2rgb_create_converter; this->set_gamma = yuv2rgb_set_gamma; this->get_gamma = yuv2rgb_get_gamma; + this->dispose = yuv2rgb_factory_dispose; this->matrix_coefficients = 6; + this->table_base = NULL; yuv2rgb_setup_tables (this, mode, swapped); diff --git a/src/video_out/yuv2rgb.h b/src/video_out/yuv2rgb.h index b27c45bdc..36ea94229 100644 --- a/src/video_out/yuv2rgb.h +++ b/src/video_out/yuv2rgb.h @@ -56,6 +56,11 @@ struct yuv2rgb_s { */ int (*next_slice) (yuv2rgb_t *this, uint8_t **dest); + /* + * free resources + */ + void (*dispose) (yuv2rgb_t *this); + /* * this is the function to call for the yuv2rgb and scaling process */ @@ -118,7 +123,12 @@ struct yuv2rgb_factory_s { * get gamma value */ int (*get_gamma) (yuv2rgb_factory_t *this); - + + /* + * free resources + */ + void (*dispose) (yuv2rgb_factory_t *this); + /* private data */ int mode; @@ -130,6 +140,7 @@ struct yuv2rgb_factory_s { uint32_t matrix_coefficients; + void *table_base; void *table_rV[256]; void *table_gU[256]; int table_gV[256]; -- cgit v1.2.3