comparison mpegvideo.c @ 5427:5a61305cc568 libavcodec

fix mem leak patch by Daniel Kristjansson: [danielk cuymedia net] Original thread: [FFmpeg-devel] [PATCH] alloc_picture needs to free buffer when it's not going to use it Date: 07/20/2007 07:27 PM
author benoit
date Tue, 31 Jul 2007 14:51:21 +0000
parents 07844149dfa9
children ce0db8111f94
comparison
equal deleted inserted replaced
5426:0e1fbd77bf55 5427:5a61305cc568
186 const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) does not sig11 186 const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) does not sig11
187 const int mb_array_size= s->mb_stride*s->mb_height; 187 const int mb_array_size= s->mb_stride*s->mb_height;
188 const int b8_array_size= s->b8_stride*s->mb_height*2; 188 const int b8_array_size= s->b8_stride*s->mb_height*2;
189 const int b4_array_size= s->b4_stride*s->mb_height*4; 189 const int b4_array_size= s->b4_stride*s->mb_height*4;
190 int i; 190 int i;
191 int r= -1;
191 192
192 if(shared){ 193 if(shared){
193 assert(pic->data[0]); 194 assert(pic->data[0]);
194 assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED); 195 assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED);
195 pic->type= FF_BUFFER_TYPE_SHARED; 196 pic->type= FF_BUFFER_TYPE_SHARED;
196 }else{ 197 }else{
197 int r;
198
199 assert(!pic->data[0]); 198 assert(!pic->data[0]);
200 199
201 r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic); 200 r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic);
202 201
203 if(r<0 || !pic->age || !pic->type || !pic->data[0]){ 202 if(r<0 || !pic->age || !pic->type || !pic->data[0]){
205 return -1; 204 return -1;
206 } 205 }
207 206
208 if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){ 207 if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){
209 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n"); 208 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n");
209 s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
210 return -1; 210 return -1;
211 } 211 }
212 212
213 if(pic->linesize[1] != pic->linesize[2]){ 213 if(pic->linesize[1] != pic->linesize[2]){
214 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n"); 214 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n");
215 s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
215 return -1; 216 return -1;
216 } 217 }
217 218
218 s->linesize = pic->linesize[0]; 219 s->linesize = pic->linesize[0];
219 s->uvlinesize= pic->linesize[1]; 220 s->uvlinesize= pic->linesize[1];
259 if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE) 260 if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE)
260 pic->age= INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway. 261 pic->age= INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway.
261 262
262 return 0; 263 return 0;
263 fail: //for the CHECKED_ALLOCZ macro 264 fail: //for the CHECKED_ALLOCZ macro
265 if(r>=0)
266 s->avctx->release_buffer(s->avctx, (AVFrame*)pic);
264 return -1; 267 return -1;
265 } 268 }
266 269
267 /** 270 /**
268 * deallocates a picture 271 * deallocates a picture