[FFmpeg-cvslog] avcodec/mpegvideo: Use av_memdup() for allocating thread_context

Michael Niedermayer git at videolan.org
Sat Jun 6 22:59:24 CEST 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Jun  6 21:28:54 2015 +0200| [46428ea332d8afa3f598d6a9d660716a4f90da6d] | committer: Michael Niedermayer

avcodec/mpegvideo: Use av_memdup() for allocating thread_context

Also check for allocation failure

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=46428ea332d8afa3f598d6a9d660716a4f90da6d
---

 libavcodec/mpegvideo.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 839dc23..e6e5326 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1290,8 +1290,9 @@ av_cold int ff_mpv_common_init(MpegEncContext *s)
         if (nb_slices > 1) {
             for (i = 0; i < nb_slices; i++) {
                 if (i) {
-                    s->thread_context[i] = av_malloc(sizeof(MpegEncContext));
-                    memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
+                    s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext));
+                    if (!s->thread_context[i])
+                        goto fail;
                 }
                 if (init_duplicate_context(s->thread_context[i]) < 0)
                     goto fail;
@@ -1418,8 +1419,11 @@ int ff_mpv_common_frame_size_change(MpegEncContext *s)
         if (nb_slices > 1) {
             for (i = 0; i < nb_slices; i++) {
                 if (i) {
-                    s->thread_context[i] = av_malloc(sizeof(MpegEncContext));
-                    memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
+                    s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext));
+                    if (!s->thread_context[i]) {
+                        err = AVERROR(ENOMEM);
+                        goto fail;
+                    }
                 }
                 if ((err = init_duplicate_context(s->thread_context[i])) < 0)
                     goto fail;



More information about the ffmpeg-cvslog mailing list