diff mbox series

Fix coverity #292159

Message ID 20200421122131.16015-1-sbabic@denx.de
State Accepted
Headers show
Series Fix coverity #292159 | expand

Commit Message

Stefano Babic April 21, 2020, 12:21 p.m. UTC
Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/installer.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/core/installer.c b/core/installer.c
index 1f6c862..82b5d60 100644
--- a/core/installer.c
+++ b/core/installer.c
@@ -255,12 +255,13 @@  int install_single_image(struct img_type *img, int dry_run)
 int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 {
 	int ret;
-	struct img_type *img;
+	struct img_type *img, *tmp;
 	char *filename;
 	struct filehdr fdh;
 	struct stat buf;
 	const char* TMPDIR = get_tmpdir();
 	int dry_run = sw->globals.dry_run;
+	bool dropimg;
 
 	/* Extract all scripts, preinstall scripts must be run now */
 	const char* tmpdir_scripts = get_tmpdirscripts();
@@ -280,7 +281,9 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 		}
 	}
 
-	LIST_FOREACH(img, &sw->images, next) {
+	LIST_FOREACH_SAFE(img, &sw->images, next, tmp) {
+
+		dropimg = false;
 
 		/*
 		 *  If image is flagged to be installed from stream
@@ -336,7 +339,7 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 					break;
 				}
 			}
-			free_image(img);
+			dropimg = true;
 			ret = 0;
 		} else {
 			ret = install_single_image(img, dry_run);
@@ -345,9 +348,11 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 		if (!fromfile)
 			close(img->fdin);
 
+		if (dropimg)
+			free_image(img);
+
 		if (ret)
 			return ret;
-
 	}
 
 	/*