diff mbox series

[FFmpeg-devel,7/7] avutil/frame: Treat frame as uninitialized in get_frame_defaults()

Message ID AM7PR03MB66600FAA96C96713C3A162FA8F6A9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 6c57e0b4a8825de01e363bc6a6ab598aaf4188e4
Headers show
Series [FFmpeg-devel,1/4] fftools/cmdutils: Atomically add elements to list of pointers, fix crash
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 3, 2021, 8:45 p.m. UTC
Currently, it also tests whether extended_data points to something
different than the AVFrame's data array and frees extended_data
if it is different. Yet this is only necessary for one of its three
callers, namely av_frame_unref(); meanwhile the other two callers
took measures to avoid this (or rather, to make it to an av_free(NULL)).

This commit moves this chunk to av_frame_unref() (so that
get_frame_defaults() now treats its input as uninitialized)
and removes the now superfluous code in the other two callers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
No code actually tests the scenario in which data != extended_data.
Of the 7984267 calls to get_frame_defaults() during FATE, 2784297
freed the extended_data, but in all these scenarios (which all came
from av_frame_alloc() and av_frame_move_ref()) extended_data was NULL.

 libavutil/frame.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/frame.c b/libavutil/frame.c
index d4d3ad6988..95bdc0be72 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -52,9 +52,6 @@  const char *av_get_colorspace_name(enum AVColorSpace val)
 #endif
 static void get_frame_defaults(AVFrame *frame)
 {
-    if (frame->extended_data != frame->data)
-        av_freep(&frame->extended_data);
-
     memset(frame, 0, sizeof(*frame));
 
     frame->pts                   =
@@ -98,12 +95,11 @@  static void wipe_side_data(AVFrame *frame)
 
 AVFrame *av_frame_alloc(void)
 {
-    AVFrame *frame = av_mallocz(sizeof(*frame));
+    AVFrame *frame = av_malloc(sizeof(*frame));
 
     if (!frame)
         return NULL;
 
-    frame->extended_data = NULL;
     get_frame_defaults(frame);
 
     return frame;
@@ -455,6 +451,9 @@  void av_frame_unref(AVFrame *frame)
     av_buffer_unref(&frame->opaque_ref);
     av_buffer_unref(&frame->private_ref);
 
+    if (frame->extended_data != frame->data)
+        av_freep(&frame->extended_data);
+
     get_frame_defaults(frame);
 }
 
@@ -466,7 +465,6 @@  void av_frame_move_ref(AVFrame *dst, AVFrame *src)
     *dst = *src;
     if (src->extended_data == src->data)
         dst->extended_data = dst->data;
-    memset(src, 0, sizeof(*src));
     get_frame_defaults(src);
 }