Commit 46428ea3 authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/mpegvideo: Use av_memdup() for allocating thread_context

Also check for allocation failure
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 7ddedd23
...@@ -1290,8 +1290,9 @@ av_cold int ff_mpv_common_init(MpegEncContext *s) ...@@ -1290,8 +1290,9 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
if (nb_slices > 1) { if (nb_slices > 1) {
for (i = 0; i < nb_slices; i++) { for (i = 0; i < nb_slices; i++) {
if (i) { if (i) {
s->thread_context[i] = av_malloc(sizeof(MpegEncContext)); s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext));
memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); if (!s->thread_context[i])
goto fail;
} }
if (init_duplicate_context(s->thread_context[i]) < 0) if (init_duplicate_context(s->thread_context[i]) < 0)
goto fail; goto fail;
...@@ -1418,8 +1419,11 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s) ...@@ -1418,8 +1419,11 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s)
if (nb_slices > 1) { if (nb_slices > 1) {
for (i = 0; i < nb_slices; i++) { for (i = 0; i < nb_slices; i++) {
if (i) { if (i) {
s->thread_context[i] = av_malloc(sizeof(MpegEncContext)); s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext));
memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); if (!s->thread_context[i]) {
err = AVERROR(ENOMEM);
goto fail;
}
} }
if ((err = init_duplicate_context(s->thread_context[i])) < 0) if ((err = init_duplicate_context(s->thread_context[i])) < 0)
goto fail; goto fail;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment