Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] tests/api/api-seek-test: Add proper error handling to avoid potential memory leaks
@ 2025-08-08 19:42 Jiasheng Jiang
  0 siblings, 0 replies; only message in thread
From: Jiasheng Jiang @ 2025-08-08 19:42 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Jiasheng Jiang

Add proper error handling to free allocated memory to avoid potential memory leaks.

Fixes: e23a01c06d ("api-seek-test: first version")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 tests/api/api-seek-test.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/tests/api/api-seek-test.c b/tests/api/api-seek-test.c
index 1bf9a1bde7..bb7ca2d1af 100644
--- a/tests/api/api-seek-test.c
+++ b/tests/api/api-seek-test.c
@@ -95,7 +95,7 @@ static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
         printf("Seeking to %"PRId64", computing crc for frames with pts < %"PRId64"\n", ts_start, ts_end);
         if (result < 0) {
             av_log(NULL, AV_LOG_ERROR, "Error in seeking\n");
-            return result;
+            goto finish;
         }
         avcodec_flush_buffers(ctx);
     }
@@ -112,7 +112,8 @@ static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
         else {
             if (pkt->pts == AV_NOPTS_VALUE) {
                 av_log(NULL, AV_LOG_ERROR, "Error: frames doesn't have pts values\n");
-                return -1;
+                result = -1;
+                goto finish;
             }
             result = avcodec_send_packet(ctx, pkt);
         }
@@ -121,7 +122,7 @@ static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
 
         if (result < 0) {
             av_log(NULL, AV_LOG_ERROR, "Error submitting a packet for decoding\n");
-            return result;
+            goto finish;
         }
 
         while (result >= 0) {
@@ -133,7 +134,7 @@ static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
                 break;
             } else if (result < 0) {
                 av_log(NULL, AV_LOG_ERROR, "Error decoding frame\n");
-                return result;
+                goto finish;
             }
 
             number_of_written_bytes = av_image_copy_to_buffer(byte_buffer, byte_buffer_size,
@@ -141,7 +142,8 @@ static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
                                     ctx->pix_fmt, ctx->width, ctx->height, 1);
             if (number_of_written_bytes < 0) {
                 av_log(NULL, AV_LOG_ERROR, "Can't copy image to buffer\n");
-                return number_of_written_bytes;
+                result = number_of_written_bytes;
+                goto finish;
             }
             if ((!no_seeking) && (fr->pts > ts_end))
                 break;
@@ -149,20 +151,24 @@ static int compute_crc_of_packets(AVFormatContext *fmt_ctx, int video_stream,
             printf("%10"PRId64", 0x%08"PRIx32"\n", fr->pts, crc);
             if (no_seeking) {
                 if (add_crc_to_array(crc, fr->pts) < 0)
-                    return -1;
+                    result = -1;
+                    goto finish;
             }
             else {
                 if (compare_crc_in_array(crc, fr->pts) < 0)
-                    return -1;
+                    result = -1;
+                    goto finish;
             }
             av_frame_unref(fr);
         }
     } while (result >= 0 && (no_seeking || (fr->pts + fr->duration <= ts_end)));
 
+    result = 0;
+
 finish:
     av_freep(&byte_buffer);
 
-    return 0;
+    return result;
 }
 
 static long int read_seek_range(const char *string_with_number)
-- 
2.25.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".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-08-08 19:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-08 19:42 [FFmpeg-devel] [PATCH] tests/api/api-seek-test: Add proper error handling to avoid potential memory leaks Jiasheng Jiang

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git