[FFmpeg-devel] [PATCH] avcodec_copy_context()
Benoit Fouet
benoit.fouet
Wed Mar 31 11:18:47 CEST 2010
Hi,
On Tue, 30 Mar 2010 14:23:03 -0400 Ronald S. Bultje wrote:
> Index: ffmpeg-svn/libavcodec/options.c
> ===================================================================
> --- ffmpeg-svn.orig/libavcodec/options.c 2010-03-29 13:37:31.000000000 -0400
> +++ ffmpeg-svn/libavcodec/options.c 2010-03-29 13:37:49.000000000 -0400
> @@ -471,3 +471,55 @@
> return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);
> }
>
> +int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
> +{
> + memcpy(dest, src, sizeof(*dest));
> +
> + /* set values specific to opened codecs back to their default state */
> + dest->priv_data = NULL;
> + dest->codec = NULL;
> + dest->palctrl = NULL;
> + dest->slice_offset = NULL;
> + dest->internal_buffer = NULL;
> + dest->hwaccel = NULL;
> + dest->execute = NULL;
> + dest->execute2 = NULL;
> + dest->reget_buffer = NULL;
> + dest->thread_opaque = NULL;
I'd add all the ones below, that you are going to override, in this
initialization list, that will ease your pain in case of error (see
below).
> +
> + /* reallocate values that should be allocated separately */
> + if (dest->rc_eq) {
Just for consistency, this should be testing src->rc_eq.
> + dest->rc_eq = av_strdup(src->rc_eq);
> + if (!dest->rc_eq)
> + return AVERROR(ENOMEM);
> + }
> + if (src->extradata && src->extradata_size > 0) {
> + dest->extradata = av_malloc(src->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
> + if (!dest->extradata)
> + return AVERROR(ENOMEM);
This is leaking rc_eq; and all the other 'return AVERROR(ENOMEM)' are
leaking something more. You should consider using a goto, or add a
function for cleaning purpose.
Ben
More information about the ffmpeg-devel
mailing list