]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cbs_sei.c
avcodec/exr: Return correct error code on allocation failure
[ffmpeg] / libavcodec / cbs_sei.c
index c49830ad77e90983607dd48dacc51877b095eff6..141e97ec588a79b808be99c075f00c44558db0d8 100644 (file)
@@ -166,7 +166,7 @@ static int cbs_sei_get_unit(CodedBitstreamContext *ctx,
         }
         if (i < 0) {
             // No VCL units; just put it at the end.
-            position = -1;
+            position = au->nb_units;
         } else {
             position = i + 1;
         }
@@ -262,14 +262,6 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
     if (!desc)
         return AVERROR(EINVAL);
 
-    if (payload_buf) {
-        payload_ref = av_buffer_ref(payload_buf);
-        if (!payload_ref)
-            return AVERROR(ENOMEM);
-    } else {
-        payload_ref = NULL;
-    }
-
     // Find an existing SEI unit or make a new one to add to.
     err = cbs_sei_get_unit(ctx, au, prefix, &unit);
     if (err < 0)
@@ -285,6 +277,14 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx,
     if (err < 0)
         return err;
 
+    if (payload_buf) {
+        payload_ref = av_buffer_ref(payload_buf);
+        if (!payload_ref)
+            return AVERROR(ENOMEM);
+    } else {
+        payload_ref = NULL;
+    }
+
     message = &list->messages[list->nb_messages - 1];
 
     message->payload_type = payload_type;