Properly free decoder_ctx on failure to prevent a memory leak during 
initialization.

Signed-off-by: 0xBat <[email protected]>
---
 doc/examples/hw_decode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/doc/examples/hw_decode.c b/doc/examples/hw_decode.c
index ac4e445505..ce18814760 100644
--- a/doc/examples/hw_decode.c
+++ b/doc/examples/hw_decode.c
@@ -215,8 +215,10 @@ int main(int argc, char *argv[])
         return AVERROR(ENOMEM);
 
     video = input_ctx->streams[video_stream];
-    if (avcodec_parameters_to_context(decoder_ctx, video->codecpar) < 0)
+    if (avcodec_parameters_to_context(decoder_ctx, video->codecpar) < 0) {
+        avcodec_free_context(&decoder_ctx);
         return -1;
+    }
 
     decoder_ctx->get_format  = get_hw_format;
 
-- 
2.52.0.windows.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to