Skip to content

Commit

Permalink
Fix a potential resource leak and add alloc checks
Browse files Browse the repository at this point in the history
Backport fixes from libaom:
https://aomedia-review.googlesource.com/c/aom/+/109061
https://aomedia-review.googlesource.com/c/aom/+/158102

Change-Id: Ia9d42d474be2898f9ae2fdc28606273377da3e90
  • Loading branch information
wantehchang committed Sep 29, 2023
1 parent 4697b11 commit 7f568f9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion examples/resize_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int main(int argc, char *argv[]) {
uint8_t *inbuf_v, *outbuf_v;
int f, frames;
int width, height, target_width, target_height;
int failed = 0;

exec_name = argv[0];

Expand Down Expand Up @@ -82,6 +83,7 @@ int main(int argc, char *argv[]) {
}
fpout = fopen(fout, "wb");
if (fpout == NULL) {
fclose(fpin);
printf("Can't open file %s to write\n", fout);
usage();
return 1;
Expand All @@ -100,6 +102,11 @@ int main(int argc, char *argv[]) {

inbuf = (uint8_t *)malloc(width * height * 3 / 2);
outbuf = (uint8_t *)malloc(target_width * target_height * 3 / 2);
if (!(inbuf && outbuf)) {
printf("Failed to allocate buffers.\n");
failed = 1;
goto Error;
}
inbuf_u = inbuf + width * height;
inbuf_v = inbuf_u + width * height / 4;
outbuf_u = outbuf + target_width * target_height;
Expand All @@ -114,10 +121,11 @@ int main(int argc, char *argv[]) {
f++;
}
printf("%d frames processed\n", f);
Error:
fclose(fpin);
fclose(fpout);

free(inbuf);
free(outbuf);
return 0;
return failed;
}

0 comments on commit 7f568f9

Please sign in to comment.