diff mbox

[U-Boot,11/14] mkimage: Fix missing free() and close() in fit_build()

Message ID 1458135945-13385-12-git-send-email-sjg@chromium.org
State Accepted
Commit 7b0bbd886d553c3cffc5b3eb29256b05856076ee
Delegated to: Tom Rini
Headers show

Commit Message

Simon Glass March 16, 2016, 1:45 p.m. UTC
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>
---

 tools/fit_image.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Tom Rini March 17, 2016, 2:09 a.m. UTC | #1
On Wed, Mar 16, 2016 at 07:45:41AM -0600, Simon Glass wrote:

> 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>
Tom Rini March 23, 2016, 2 a.m. UTC | #2
On Wed, Mar 16, 2016 at 07:45:41AM -0600, Simon Glass wrote:

> 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>

Applied to u-boot/master, thanks!
diff mbox

Patch

diff --git a/tools/fit_image.c b/tools/fit_image.c
index e628212..9d553d1 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -329,7 +329,7 @@  static int fit_build(struct image_tool_params *params, const char *fname)
 	if (ret < 0) {
 		fprintf(stderr, "%s: Failed to build FIT image\n",
 			params->cmdname);
-		goto err;
+		goto err_buf;
 	}
 	size = ret;
 	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;
 	}
 	close(fd);
+	free(buf);
 
 	return 0;
 err:
+	close(fd);
+err_buf:
 	free(buf);
 	return -1;
 }