ref: c7342f35c8ac392ec3a10a538607fb2f8f7b2564
parent: f62dcc9c334eb5060293cbf0cfd7de82bb4ea78c
author: Johann <[email protected]>
date: Tue Jan 31 10:58:43 EST 2017
tiny_ssim: clean up on failure Clears up clang static analysis warnings about memory leaks. Change-Id: I60d4d0f3794735a8b81d9da4a30d19e7a9cba9cf
--- a/tools/tiny_ssim.c
+++ b/tools/tiny_ssim.c
@@ -117,7 +117,7 @@
}
int main(int argc, char *argv[]) {
- FILE *f[2], *framestats = NULL;
+ FILE *f[2] = { NULL, NULL }, *framestats = NULL;
uint8_t *buf[2];
int w, h, tl_skip = 0, tl_skips_remaining = 0;
double ssimavg = 0, ssimyavg = 0, ssimuavg = 0, ssimvavg = 0;
@@ -126,6 +126,7 @@
double *ssimy = NULL, *ssimu = NULL, *ssimv = NULL;
uint64_t *psnry = NULL, *psnru = NULL, *psnrv = NULL;
size_t i, n_frames = 0, allocated_frames = 0;
+ int return_value = 0;
if (argc < 4 || argc > 6) {
fprintf(stderr,
@@ -132,7 +133,8 @@
"Usage: %s file1.yuv file2.yuv WxH [tl_skip={0,1,3}] "
"[framestats.csv]\n",
argv[0]);
- return 1;
+ return_value = 1;
+ goto clean_up;
}
f[0] = strcmp(argv[1], "-") ? fopen(argv[1], "rb") : stdin;
f[1] = strcmp(argv[2], "-") ? fopen(argv[2], "rb") : stdin;
@@ -147,17 +149,20 @@
if (!framestats) {
fprintf(stderr, "Could not open \"%s\" for writing: %s\n", argv[5],
strerror(errno));
- return 1;
+ return_value = 1;
+ goto clean_up;
}
}
}
if (!f[0] || !f[1]) {
fprintf(stderr, "Could not open input files: %s\n", strerror(errno));
- return 1;
+ return_value = 1;
+ goto clean_up;
}
if (w <= 0 || h <= 0 || w & 1 || h & 1) {
fprintf(stderr, "Invalid size %dx%d\n", w, h);
- return 1;
+ return_value = 1;
+ goto clean_up;
}
buf[0] = malloc(w * h * 3 / 2);
buf[1] = malloc(w * h * 3 / 2);
@@ -177,7 +182,8 @@
if (r1 && r2 && r1 != r2) {
fprintf(stderr, "Failed to read data: %s [%d/%d]\n", strerror(errno),
(int)r1, (int)r2);
- return 1;
+ return_value = 1;
+ goto clean_up;
} else if (r1 == 0 || r2 == 0) {
break;
}
@@ -278,8 +284,9 @@
printf("Nframes: %d\n", (int)n_frames);
- if (strcmp(argv[1], "-")) fclose(f[0]);
- if (strcmp(argv[2], "-")) fclose(f[1]);
+clean_up:
+ if (f[0] && strcmp(argv[1], "-")) fclose(f[0]);
+ if (f[1] && strcmp(argv[2], "-")) fclose(f[1]);
if (framestats) fclose(framestats);
free(ssimy);
@@ -290,5 +297,5 @@
free(psnru);
free(psnrv);
- return 0;
+ return return_value;
}