diff mbox series

[FFmpeg-devel,2/2] avformat/bethsoftvid: Fix potential memleak upon reallocation failure

Message ID 20200321025732.7614-2-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/2] avformat/bethsoftvid: Avoid allocations and frees for palettes
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt March 21, 2020, 2:57 a.m. UTC
The classical ptr = av_realloc(ptr, size), just with av_fast_realloc().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/bethsoftvid.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Paul B Mahol March 21, 2020, 9:29 a.m. UTC | #1
LGTM

On 3/21/20, Andreas Rheinhardt <andreas.rheinhardt@gmail.com> wrote:
> The classical ptr = av_realloc(ptr, size), just with av_fast_realloc().
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/bethsoftvid.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c
> index e52b17433c..c54c54325a 100644
> --- a/libavformat/bethsoftvid.c
> +++ b/libavformat/bethsoftvid.c
> @@ -147,9 +147,13 @@ static int read_frame(BVID_DemuxContext *vid,
> AVIOContext *pb, AVPacket *pkt,
>      }
>
>      do{
> -        vidbuf_start = av_fast_realloc(vidbuf_start, &vidbuf_capacity,
> vidbuf_nbytes + BUFFER_PADDING_SIZE);
> -        if(!vidbuf_start)
> -            return AVERROR(ENOMEM);
> +        uint8_t *tmp = av_fast_realloc(vidbuf_start, &vidbuf_capacity,
> +                                       vidbuf_nbytes +
> BUFFER_PADDING_SIZE);
> +        if (!tmp) {
> +            ret = AVERROR(ENOMEM);
> +            goto fail;
> +        }
> +        vidbuf_start = tmp;
>
>          code = avio_r8(pb);
>          vidbuf_start[vidbuf_nbytes++] = code;
> --
> 2.20.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Michael Niedermayer March 22, 2020, 12:04 p.m. UTC | #2
On Sat, Mar 21, 2020 at 10:29:26AM +0100, Paul B Mahol wrote:
> LGTM

will apply

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/bethsoftvid.c b/libavformat/bethsoftvid.c
index e52b17433c..c54c54325a 100644
--- a/libavformat/bethsoftvid.c
+++ b/libavformat/bethsoftvid.c
@@ -147,9 +147,13 @@  static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt,
     }
 
     do{
-        vidbuf_start = av_fast_realloc(vidbuf_start, &vidbuf_capacity, vidbuf_nbytes + BUFFER_PADDING_SIZE);
-        if(!vidbuf_start)
-            return AVERROR(ENOMEM);
+        uint8_t *tmp = av_fast_realloc(vidbuf_start, &vidbuf_capacity,
+                                       vidbuf_nbytes + BUFFER_PADDING_SIZE);
+        if (!tmp) {
+            ret = AVERROR(ENOMEM);
+            goto fail;
+        }
+        vidbuf_start = tmp;
 
         code = avio_r8(pb);
         vidbuf_start[vidbuf_nbytes++] = code;