Rework error handling in transcode_setup()

Add the setup_fail_codec label and jump to it if an error occurs once the
codec has been opened. In the raw input codepath, don't use this label until
the file is properly opened, as it also closes the fd and frees the raw
buffer.

This also fixes a file descriptor leak in the case where an error happened
after the file was opened in the raw input codepath.
This commit is contained in:
Julien BLACHE 2010-03-15 18:35:29 +01:00
parent db0690afa1
commit 8375ac75ca

View File

@ -415,9 +415,7 @@ transcode_setup(struct media_file_info *mfi, off_t *est_size)
else
DPRINTF(E_WARN, L_XCODE, "Could not read enough raw data\n");
free(ctx->rawbuffer);
avcodec_close(ctx->acodec);
goto setup_fail;
goto setup_fail_codec;
}
ret = has_id3v2_tag(ctx->rawbuffer);
@ -434,9 +432,7 @@ transcode_setup(struct media_file_info *mfi, off_t *est_size)
{
DPRINTF(E_WARN, L_XCODE, "Could not seek: %s\n", strerror(errno));
free(ctx->rawbuffer);
avcodec_close(ctx->acodec);
goto setup_fail;
goto setup_fail_codec;
}
}
@ -448,13 +444,7 @@ transcode_setup(struct media_file_info *mfi, off_t *est_size)
{
DPRINTF(E_WARN, L_XCODE, "Could not allocate transcode buffer\n");
if (ctx->fd != -1)
{
close(ctx->fd);
free(ctx->rawbuffer);
}
avcodec_close(ctx->acodec);
goto setup_fail;
goto setup_fail_codec;
}
ctx->duration = mfi->song_length;
@ -464,9 +454,18 @@ transcode_setup(struct media_file_info *mfi, off_t *est_size)
return ctx;
setup_fail_codec:
if (ctx->fd != -1)
{
close(ctx->fd);
free(ctx->rawbuffer);
}
avcodec_close(ctx->acodec);
setup_fail:
av_close_input_file(ctx->fmtctx);
free(ctx);
return NULL;
}