Selaa lähdekoodia

mkimage: Fix missing free() and close() in fit_build()

Make sure that both the error path and normal return free the buffer and
close the file.

Reported-by: Coverity (CID: 138491)
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>
Simon Glass 9 vuotta sitten
vanhempi
commit
7b0bbd886d
1 muutettua tiedostoa jossa 4 lisäystä ja 1 poistoa
  1. 4 1
      tools/fit_image.c

+ 4 - 1
tools/fit_image.c

@@ -329,7 +329,7 @@ static int fit_build(struct image_tool_params *params, const char *fname)
 	if (ret < 0) {
 	if (ret < 0) {
 		fprintf(stderr, "%s: Failed to build FIT image\n",
 		fprintf(stderr, "%s: Failed to build FIT image\n",
 			params->cmdname);
 			params->cmdname);
-		goto err;
+		goto err_buf;
 	}
 	}
 	size = ret;
 	size = ret;
 	fd = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
 	fd = open(fname, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0666);
@@ -346,9 +346,12 @@ static int fit_build(struct image_tool_params *params, const char *fname)
 		goto err;
 		goto err;
 	}
 	}
 	close(fd);
 	close(fd);
+	free(buf);
 
 
 	return 0;
 	return 0;
 err:
 err:
+	close(fd);
+err_buf:
 	free(buf);
 	free(buf);
 	return -1;
 	return -1;
 }
 }