comparison utils.c @ 10255:b81ec4ac8f96 libavcodec

Make sure priv_data is freed and codec is set to NULL in case of failure of avcodec_open().
author michael
date Wed, 23 Sep 2009 15:16:36 +0000
parents bd1c4a438c7f
children 294c444866f7
comparison
equal deleted inserted replaced
10254:b9f5f8b8f073 10255:b81ec4ac8f96
473 473
474 #define SANE_NB_CHANNELS 128U 474 #define SANE_NB_CHANNELS 128U
475 if (((avctx->coded_width || avctx->coded_height) 475 if (((avctx->coded_width || avctx->coded_height)
476 && avcodec_check_dimensions(avctx, avctx->coded_width, avctx->coded_height)) 476 && avcodec_check_dimensions(avctx, avctx->coded_width, avctx->coded_height))
477 || avctx->channels > SANE_NB_CHANNELS) { 477 || avctx->channels > SANE_NB_CHANNELS) {
478 av_freep(&avctx->priv_data);
479 ret = AVERROR(EINVAL); 478 ret = AVERROR(EINVAL);
480 goto end; 479 goto free_and_end;
481 } 480 }
482 481
483 avctx->codec = codec; 482 avctx->codec = codec;
484 if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){ 483 if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){
485 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n"); 484 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
486 goto end; 485 goto free_and_end;
487 } 486 }
488 avctx->frame_number = 0; 487 avctx->frame_number = 0;
489 if(avctx->codec->init){ 488 if(avctx->codec->init){
490 ret = avctx->codec->init(avctx); 489 ret = avctx->codec->init(avctx);
491 if (ret < 0) { 490 if (ret < 0) {
492 av_freep(&avctx->priv_data); 491 goto free_and_end;
493 avctx->codec= NULL;
494 goto end;
495 } 492 }
496 } 493 }
497 ret=0; 494 ret=0;
498 end: 495 end:
499 entangled_thread_counter--; 496 entangled_thread_counter--;
501 /* Release any user-supplied mutex. */ 498 /* Release any user-supplied mutex. */
502 if (ff_lockmgr_cb) { 499 if (ff_lockmgr_cb) {
503 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); 500 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
504 } 501 }
505 return ret; 502 return ret;
503 free_and_end:
504 av_freep(&avctx->priv_data);
505 avctx->codec= NULL;
506 goto end;
506 } 507 }
507 508
508 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, 509 int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
509 const short *samples) 510 const short *samples)
510 { 511 {