From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id E929B4CCB0 for ; Fri, 8 Aug 2025 19:42:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 9D21068CC39; Fri, 8 Aug 2025 22:42:33 +0300 (EEST) Received: from mail-io1-f54.google.com (mail-io1-f54.google.com [209.85.166.54]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 1075E68B75A for ; Fri, 8 Aug 2025 22:42:27 +0300 (EEST) Received: by mail-io1-f54.google.com with SMTP id ca18e2360f4ac-8818bb36b5bso165927439f.1 for ; Fri, 08 Aug 2025 12:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754682145; x=1755286945; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=uXj2oulrAiAdHRomuzl2Zgd3fXPJ5pIjfxRuPQg1dJc=; b=k9BtQXRrgbaN8IQ4ujt5qez7OYBCevsB2h73zV/m5mmGW2qWYzrNpLa6x/xbUPelB+ VGKgz0qmt++IONLJO4M88kP7do8MgL11v07RdohEJEVfbWSivaWaARk3v/BHVlaaAbFn VBCgbrYgwWgo/EPfGY6Jce/KQGUaUJIX0jZMvm5C1RkaXs4OzM5ox0lLnG1XeVqU2QvX rS6xF2i2RCD+CUMh4F5FSTCpoXsY+k1ZdLJNyTYauPcwM+KwqUBxShWXZ0kCoLMRwOBc o5FvLmBNua/6+TXpv5zt2l3+9zsecvwa5Kk6qNTP+c+OFm45WkQ3fHWCvbzP7yTxLbOW SyEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754682145; x=1755286945; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uXj2oulrAiAdHRomuzl2Zgd3fXPJ5pIjfxRuPQg1dJc=; b=LH/SRw5tD1vNdauzjCCaEuV3Rmk1hDkHFUOX7hm/A3rdUWQDpNL6t43DocINGYHnGj hnUG35/xZw930RBFKoLqKLehiyK3BPJm+t3wSSv9Ll65pNxhURo48Kndwgzo3A6h+3yZ i31VWzkyu+3Su8KtPhAtxkUZqK+mADx26Fd1AslIQTQI+j2TuIGpvELSeWq0TkvBdcTb 5JL0yAbfKEeYRqMzLq2YxQxON1HimP/d48l3z2xLkXxLgdgDL8o+1QRfAA3rDA9w7LXY Vni6TiJ2PrlTro1S6q5LsSf4wio2c2JjlWnGZ7IFNobdj1pxEZ+XGUSRoDidlQ3aLEW9 ToJA== X-Gm-Message-State: AOJu0YyizSLdUYYb23ppveUInjRbVeN+/EgM1MHgfYW0J0jGwdQ1SZL4 pLHnhJtsrCmWWKSRpv5s3h4CVdcd1+pchxSk+oImeZwVBGP5msX0wbjr5FUklg== X-Gm-Gg: ASbGncsKRDRs1TeWFQlOoVuPc26P4IFVcbEqr3K7ID5xgity5qO/ZpRtWSHiYbZNVkz TJfPT4RzkW4xwEr8C8AQXTlKFgx2uKtrPp/baRc2inGFBR/bVjkfV0FMKfv6YYEDt1ppMDZdLSb brjXuGRBdUi628FXhXddXJfcA2Dm9Vq8ou/ioB4939MbwJm7huk7pTZhNl+K4o800e4gl9BNJfp KbkgKcFCN/0CVrsHmaHgjqCadjUURL8aQvDjpNLoGRLEXRs1PESEfL8si8jwFm/lGJpg6sfCjRe wjY9YjeW4JYRLquMsQPmEFEU2gV2pL+BzmAmc2lPo7pv5wiONTW6vItEvNyM3sBdTT9WJtAk5QW 8zTsX0BOV7Gy+RkCG7cmN8mKWzlILJ8bqRQ8nuWah52Mq X-Google-Smtp-Source: AGHT+IFZcHlxPIvUwTn/2Oe6XgO3TwqWRh7ln5SCS4REv0+tyWeybcutgQ1BqCD5qOgqM8qBlnYCjw== X-Received: by 2002:a05:6e02:154c:b0:3e3:e732:aef6 with SMTP id e9e14a558f8ab-3e53318db81mr83408305ab.18.1754682144869; Fri, 08 Aug 2025 12:42:24 -0700 (PDT) Received: from newman.cs.purdue.edu ([128.10.127.250]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-50ae99cdc8csm653288173.27.2025.08.08.12.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Aug 2025 12:42:24 -0700 (PDT) From: Jiasheng Jiang To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Aug 2025 19:42:22 +0000 Message-Id: <20250808194222.20046-1-jiashengjiangcool@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] tests/api/api-seek-test: Add proper error handling to avoid potential memory leaks X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Jiasheng Jiang Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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 --- 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".