]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/avcodec, avpacket: Return blank packet on av_packet_ref() failure
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Fri, 27 Mar 2020 00:56:38 +0000 (01:56 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 28 Mar 2020 02:59:15 +0000 (03:59 +0100)
Up until now, it was completely unspecified what the content of the
destination packet dst was on error. Depending upon where the error
happened calling av_packet_unref() on dst might be dangerous.

This commit changes this by making sure that dst is blank on error, so
unreferencing it again is safe (and still pointless). This behaviour is
documented.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
doc/APIchanges
libavcodec/avcodec.h
libavcodec/avpacket.c
libavcodec/version.h

index 8eeaec2028e5d04a598f730ccc7997c0f5013aea..f2bb2d242b3e5bb7a85b5285ca99e77f41a8d6a1 100644 (file)
@@ -15,6 +15,10 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2020-03-27 - xxxxxxxxxx - lavc 58.77.100 - avcodec.h
+  av_packet_ref() now guarantees to return the destination packet
+  in a blank state on error.
+
 2020-03-10 - xxxxxxxxxx - lavc 58.75.100 - avcodec.h
   Add AV_PKT_DATA_ICC_PROFILE.
 
index f918d20a61561b7a990baa696b3911b58527b412..8fc0ad92c934e818a0c7905c1368b3354c21542b 100644 (file)
@@ -4651,7 +4651,8 @@ void av_packet_free_side_data(AVPacket *pkt);
  * @param dst Destination packet. Will be completely overwritten.
  * @param src Source packet
  *
- * @return 0 on success, a negative AVERROR on error.
+ * @return 0 on success, a negative AVERROR on error. On error, dst
+ *         will be blank (as if returned by av_packet_alloc()).
  */
 int av_packet_ref(AVPacket *dst, const AVPacket *src);
 
index 132567bc2d4a13dbfd683d3af7ae63b6f551c451..c622718a4522b3858954f760f27617a49c157c6b 100644 (file)
@@ -610,12 +610,13 @@ int av_packet_ref(AVPacket *dst, const AVPacket *src)
 {
     int ret;
 
+    dst->buf = NULL;
+
     ret = av_packet_copy_props(dst, src);
     if (ret < 0)
-        return ret;
+        goto fail;
 
     if (!src->buf) {
-        dst->buf = NULL;
         ret = packet_alloc(&dst->buf, src->size);
         if (ret < 0)
             goto fail;
@@ -637,7 +638,7 @@ int av_packet_ref(AVPacket *dst, const AVPacket *src)
 
     return 0;
 fail:
-    av_packet_free_side_data(dst);
+    av_packet_unref(dst);
     return ret;
 }
 
index 1f19b67adc2af4e26d0d0a29a8060fec43ce87b8..7e01d9526f85f8b3ff1ca1ac09d308649e4ed7d5 100644 (file)
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  76
+#define LIBAVCODEC_VERSION_MINOR  77
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \