From: Jiasheng Jiang <jiashengjiangcool@gmail.com> To: ffmpeg-devel@ffmpeg.org Cc: Jiasheng Jiang <jiashengjiangcool@gmail.com> Subject: [FFmpeg-devel] [PATCH] tests/api/api-seek-test: Add proper error handling to avoid potential memory leaks Date: Fri, 8 Aug 2025 19:42:22 +0000 Message-ID: <20250808194222.20046-1-jiashengjiangcool@gmail.com> (raw) 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".
reply other threads:[~2025-08-08 19:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20250808194222.20046-1-jiashengjiangcool@gmail.com \ --to=jiashengjiangcool@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
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