History

In avcodec_open(), set return code to an error value only when an error occurs instead of unconditionally at the start of the function.

This fixes a bug where a successful call to ff_thread_init() masks errors that occur after that point in the function. It also makes future bugs like this less likely since the error code is now set near to the point in the code where the error is found.

Justin Ruggles committed 15 years ago

Commit 31d76ec1 parent cda7aa91 file · +8 −3Browse files

Unified · Split

libavcodec/utils.c+8−3
@@ -456,7 +456,7 @@ AVFrame *avcodec_alloc_frame(void){ · 455 unmodified lines
456 456
457int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)457int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
458{458{
459 int ret= -1;459 int ret = 0;
460 460
461 /* If there is a user-supplied mutex locking routine, call it. */461 /* If there is a user-supplied mutex locking routine, call it. */
462 if (ff_lockmgr_cb) {462 if (ff_lockmgr_cb) {
@@ -467,11 +467,14 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 4 unmodified lines
467 entangled_thread_counter++;467 entangled_thread_counter++;
468 if(entangled_thread_counter != 1){468 if(entangled_thread_counter != 1){
469 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");469 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
470 ret = -1;
470 goto end;471 goto end;
471 }472 }
472 473
473 if(avctx->codec || !codec)474 if(avctx->codec || !codec) {
475 ret = AVERROR(EINVAL);
474 goto end;476 goto end;
477 }
475 478
476 if (codec->priv_data_size > 0) {479 if (codec->priv_data_size > 0) {
477 if(!avctx->priv_data){480 if(!avctx->priv_data){
@@ -521,6 +524,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 43 unmodified lines
521 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type524 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type
522 && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {525 && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
523 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");526 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
527 ret = AVERROR(EINVAL);
524 goto free_and_end;528 goto free_and_end;
525 }529 }
526 avctx->frame_number = 0;530 avctx->frame_number = 0;
@@ -535,6 +539,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 8 unmodified lines
535 if (avctx->codec->max_lowres < avctx->lowres) {539 if (avctx->codec->max_lowres < avctx->lowres) {
536 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",540 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
537 avctx->codec->max_lowres);541 avctx->codec->max_lowres);
542 ret = AVERROR(EINVAL);
538 goto free_and_end;543 goto free_and_end;
539 }544 }
540 if (avctx->codec->sample_fmts && avctx->codec->encode) {545 if (avctx->codec->sample_fmts && avctx->codec->encode) {
@@ -544,6 +549,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 3 unmodified lines
544 break;549 break;
545 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {550 if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
546 av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");551 av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n");
552 ret = AVERROR(EINVAL);
547 goto free_and_end;553 goto free_and_end;
548 }554 }
549 }555 }
@@ -554,7 +560,6 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 4 unmodified lines
554 goto free_and_end;560 goto free_and_end;
555 }561 }
556 }562 }
557 ret=0;
558end:563end:
559 entangled_thread_counter--;564 entangled_thread_counter--;
560 565

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t