From cb1abee1455ac7e552da271ac64c71d117caaa77 Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 6 May 2022 11:55:56 -0700 Subject: [PATCH] add some missing realloc checks Change-Id: I0fd1e094085c18b1d9a32333e876c2affeb6de23 --- examples/twopass_encoder.c | 1 + test/vp9_ethread_test.cc | 1 + tools/tiny_ssim.c | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/examples/twopass_encoder.c b/examples/twopass_encoder.c index 07ba37d..07a10d9 100644 --- a/examples/twopass_encoder.c +++ b/examples/twopass_encoder.c @@ -84,6 +84,7 @@ static int get_frame_stats(vpx_codec_ctx_t *ctx, const vpx_image_t *img, const uint8_t *const pkt_buf = pkt->data.twopass_stats.buf; const size_t pkt_size = pkt->data.twopass_stats.sz; stats->buf = realloc(stats->buf, stats->sz + pkt_size); + if (!stats->buf) die("Failed to reallocate stats buffer."); memcpy((uint8_t *)stats->buf + stats->sz, pkt_buf, pkt_size); stats->sz += pkt_size; } diff --git a/test/vp9_ethread_test.cc b/test/vp9_ethread_test.cc index 21caf79..238366c 100644 --- a/test/vp9_ethread_test.cc +++ b/test/vp9_ethread_test.cc @@ -98,6 +98,7 @@ class VPxFirstPassEncoderThreadTest firstpass_stats_.buf = realloc(firstpass_stats_.buf, firstpass_stats_.sz + pkt_size); + ASSERT_NE(firstpass_stats_.buf, nullptr); memcpy((uint8_t *)firstpass_stats_.buf + firstpass_stats_.sz, pkt_buf, pkt_size); firstpass_stats_.sz += pkt_size; diff --git a/tools/tiny_ssim.c b/tools/tiny_ssim.c index 1577970..8fba814 100644 --- a/tools/tiny_ssim.c +++ b/tools/tiny_ssim.c @@ -453,6 +453,10 @@ int main(int argc, char *argv[]) { psnry = realloc(psnry, allocated_frames * sizeof(*psnry)); psnru = realloc(psnru, allocated_frames * sizeof(*psnru)); psnrv = realloc(psnrv, allocated_frames * sizeof(*psnrv)); + if (!(ssimy && ssimu && ssimv && psnry && psnru && psnrv)) { + fprintf(stderr, "Error allocating SSIM/PSNR data.\n"); + exit(EXIT_FAILURE); + } } psnr_and_ssim(ssimy[n_frames], psnry[n_frames], y[0], y[1], w, h); psnr_and_ssim(ssimu[n_frames], psnru[n_frames], u[0], u[1], (w + 1) / 2, -- 2.7.4