diff mbox series

[FFmpeg-devel,2/5] avcodec/vbn(dec|enc): Avoid leaving stale pointers in context

Message ID AS8PR01MB794495F797FC239BD5603FAD8FED9@AS8PR01MB7944.eurprd01.prod.exchangelabs.com
State Accepted
Commit 300dd79c3d764a5d38b914bb0f36ba195422068e
Headers show
Series [FFmpeg-devel,1/5] avcodec/vbn(dec|enc): Remove empty close function | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt April 12, 2022, 7:25 p.m. UTC
Therefore move the (Get|Put)ByteContext from the context to the stack.
It is transient anyway.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/vbndec.c | 11 ++++-------
 libavcodec/vbnenc.c |  3 +--
 2 files changed, 5 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/vbndec.c b/libavcodec/vbndec.c
index 916421925d..56bfb1d544 100644
--- a/libavcodec/vbndec.c
+++ b/libavcodec/vbndec.c
@@ -34,7 +34,6 @@ 
 typedef struct VBNContext {
     TextureDSPContext texdsp;
     TextureDSPThreadContext dec;
-    GetByteContext gb;
 } VBNContext;
 
 static av_cold int vbn_init(AVCodecContext *avctx)
@@ -44,11 +43,9 @@  static av_cold int vbn_init(AVCodecContext *avctx)
     return 0;
 }
 
-static int decompress(AVCodecContext *avctx, int compression, uint8_t **outbuf)
+static int decompress(AVCodecContext *avctx, GetByteContext *gb,
+                      int compression, uint8_t **outbuf)
 {
-    VBNContext *ctx = avctx->priv_data;
-    GetByteContext *gb = &ctx->gb;
-
     if (compression == VBN_COMPRESSION_NONE) // outbuf is left NULL because gb->buf can be used directly
         return bytestream2_get_bytes_left(gb);
 
@@ -61,7 +58,7 @@  static int vbn_decode_frame(AVCodecContext *avctx,
                             AVPacket *avpkt)
 {
     VBNContext *ctx    = avctx->priv_data;
-    GetByteContext *gb = &ctx->gb;
+    GetByteContext gb0, *const gb = &gb0;
     uint8_t *image_buf = NULL;
     int      image_len;
     int width, height, components, format, compression, pix_fmt, linesize, data_size;
@@ -139,7 +136,7 @@  static int vbn_decode_frame(AVCodecContext *avctx,
         return AVERROR_PATCHWELCOME;
     }
 
-    image_len = decompress(avctx, compression, &image_buf);
+    image_len = decompress(avctx, gb, compression, &image_buf);
     if (image_len < 0)
         return image_len;
 
diff --git a/libavcodec/vbnenc.c b/libavcodec/vbnenc.c
index 0b2c4dced2..03d36ccc86 100644
--- a/libavcodec/vbnenc.c
+++ b/libavcodec/vbnenc.c
@@ -37,7 +37,6 @@ 
 typedef struct VBNContext {
     AVClass *class;
     TextureDSPContext dxtc;
-    PutByteContext pb;
     int format;
     TextureDSPThreadContext enc;
 } VBNContext;
@@ -46,7 +45,7 @@  static int vbn_encode(AVCodecContext *avctx, AVPacket *pkt,
                       const AVFrame *frame, int *got_packet)
 {
     VBNContext *ctx = avctx->priv_data;
-    PutByteContext *pb = &ctx->pb;
+    PutByteContext pb0, *const pb = &pb0;
     int ret;
     ptrdiff_t linesize;
     int64_t pkt_size;