diff mbox series

[2/5] installer: Add free_image function to always drop dictionary and free image together

Message ID 1516715761-3043-2-git-send-email-stefan@herbrechtsmeier.net
State Accepted
Headers show
Series [1/5] parser: Check image version after parsing to remove skipped images | expand

Commit Message

Stefan Herbrechtsmeier Jan. 23, 2018, 1:55 p.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
---

 core/parser.c       |  2 +-
 corelib/installer.c | 10 +++++++---
 include/swupdate.h  |  1 +
 parser/parser.c     | 19 ++++++++-----------
 4 files changed, 17 insertions(+), 15 deletions(-)

Comments

Stefano Babic Jan. 24, 2018, 9:28 a.m. UTC | #1
On 23/01/2018 14:55, stefan@herbrechtsmeier.net wrote:
> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> ---
> 
>  core/parser.c       |  2 +-
>  corelib/installer.c | 10 +++++++---
>  include/swupdate.h  |  1 +
>  parser/parser.c     | 19 ++++++++-----------
>  4 files changed, 17 insertions(+), 15 deletions(-)
> 
> diff --git a/core/parser.c b/core/parser.c
> index 0edbe1b..27c78ec 100644
> --- a/core/parser.c
> +++ b/core/parser.c
> @@ -170,7 +170,7 @@ static void remove_installed_image_list(struct imglist *img_list,
>  	LIST_FOREACH(img, img_list, next) {
>  		if (is_image_installed(sw_ver_list, img)) {
>  			LIST_REMOVE(img, next);
> -			free(img);
> +			free_image(img);
>  		}
>  	}
>  }
> diff --git a/corelib/installer.c b/corelib/installer.c
> index c630b9d..811723c 100644
> --- a/corelib/installer.c
> +++ b/corelib/installer.c
> @@ -335,7 +335,7 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
>  					break;
>  				}
>  			}
> -			free(img);
> +			free_image(img);
>  			ret = 0;
>  		} else {
>  			ret = install_single_image(img);
> @@ -386,7 +386,11 @@ static void cleaup_img_entry(struct img_type *img)
>  			}
>  		}
>  	}
> +}
> +
> +void free_image(struct img_type *img) {
>  	dict_drop_db(&img->properties);
> +	free(img);
>  }
>  
>  void cleanup_files(struct swupdate_cfg *software) {
> @@ -405,7 +409,7 @@ void cleanup_files(struct swupdate_cfg *software) {
>  			remove_sw_file(fn);
>  		}
>  		LIST_REMOVE(img, next);
> -		free(img);
> +		free_image(img);
>  	}
>  
>  	for (unsigned int count = 0; count < ARRAY_SIZE(list); count++) {
> @@ -413,7 +417,7 @@ void cleanup_files(struct swupdate_cfg *software) {
>  			cleaup_img_entry(img);
>  
>  			LIST_REMOVE(img, next);
> -			free(img);
> +			free_image(img);
>  		}
>  	}
>  
> diff --git a/include/swupdate.h b/include/swupdate.h
> index db9abbf..7de096a 100644
> --- a/include/swupdate.h
> +++ b/include/swupdate.h
> @@ -147,5 +147,6 @@ struct swupdate_cfg {
>  off_t extract_sw_description(int fd, const char *descfile, off_t start);
>  int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start);
>  struct swupdate_cfg *get_swupdate_cfg(void);
> +void free_image(struct img_type *img);
>  
>  #endif
> diff --git a/parser/parser.c b/parser/parser.c
> index 06f03b6..e07ed8e 100644
> --- a/parser/parser.c
> +++ b/parser/parser.c
> @@ -225,7 +225,6 @@ static int run_embscript(parsertype p, void *elem, struct img_type *img,
>  	if (!exist_field_string(p, elem, "hook"))
>  		return 0;
>  	embfcn = get_field_string(p, elem, "hook");
> -
>  	return lua_parser_fn(L, embfcn, img);
>  }
>  
> @@ -302,7 +301,7 @@ static int parse_partitions(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
>  			return -ENOMEM;
>  		}
>  		if (parse_common_attributes(p, elem, partition) < 0) {
> -			free(partition);
> +			free_image(partition);
>  			return -1;
>  		}
>  		GET_FIELD_STRING(p, elem, "name", partition->volname);
> @@ -315,7 +314,7 @@ static int parse_partitions(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
>  
>  		if (!strlen(partition->volname) || !strlen(partition->device)) {
>  			ERROR("Partition incompleted in description file");
> -			free(partition);
> +			free_image(partition);
>  			return -1;
>  		}
>  
> @@ -368,7 +367,7 @@ static int parse_scripts(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
>  		}
>  
>  		if (parse_common_attributes(p, elem, script) < 0) {
> -			free(script);
> +			free_image(script);
>  			return -1;
>  		}
>  
> @@ -440,7 +439,7 @@ static int parse_bootloader(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
>  		}
>  
>  		if (parse_common_attributes(p, elem, script) < 0) {
> -			free(script);
> +			free_image(script);
>  			return -1;
>  		}
>  
> @@ -489,7 +488,7 @@ static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua
>  		}
>  
>  		if (parse_common_attributes(p, elem, image) < 0) {
> -			free(image);
> +			free_image(image);
>  			return -1;
>  		}
>  
> @@ -504,8 +503,7 @@ static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua
>  		add_properties(p, elem, image);
>  
>  		if (run_embscript(p, elem, image, L, swcfg->embscript)) {
> -			dict_drop_db(&image->properties);
> -			free(image);
> +			free_image(image);
>  			return -1;
>  		}
>  
> @@ -563,7 +561,7 @@ static int parse_files(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua_
>  		}
>  
>  		if (parse_common_attributes(p, elem, file) < 0) {
> -			free(file);
> +			free_image(file);
>  			return -1;
>  		}
>  
> @@ -574,8 +572,7 @@ static int parse_files(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua_
>  		add_properties(p, elem, file);
>  
>  		if (run_embscript(p, elem, file, L, swcfg->embscript)) {
> -			dict_drop_db(&file->properties);
> -			free(file);
> +			free_image(file);
>  			return -1;
>  		}
>  
> 

Acked-by: Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
Stefano Babic Jan. 26, 2018, 9:27 a.m. UTC | #2
On 23/01/2018 14:55, stefan@herbrechtsmeier.net wrote:
> From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> 
> Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
> ---
> 
Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/core/parser.c b/core/parser.c
index 0edbe1b..27c78ec 100644
--- a/core/parser.c
+++ b/core/parser.c
@@ -170,7 +170,7 @@  static void remove_installed_image_list(struct imglist *img_list,
 	LIST_FOREACH(img, img_list, next) {
 		if (is_image_installed(sw_ver_list, img)) {
 			LIST_REMOVE(img, next);
-			free(img);
+			free_image(img);
 		}
 	}
 }
diff --git a/corelib/installer.c b/corelib/installer.c
index c630b9d..811723c 100644
--- a/corelib/installer.c
+++ b/corelib/installer.c
@@ -335,7 +335,7 @@  int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile)
 					break;
 				}
 			}
-			free(img);
+			free_image(img);
 			ret = 0;
 		} else {
 			ret = install_single_image(img);
@@ -386,7 +386,11 @@  static void cleaup_img_entry(struct img_type *img)
 			}
 		}
 	}
+}
+
+void free_image(struct img_type *img) {
 	dict_drop_db(&img->properties);
+	free(img);
 }
 
 void cleanup_files(struct swupdate_cfg *software) {
@@ -405,7 +409,7 @@  void cleanup_files(struct swupdate_cfg *software) {
 			remove_sw_file(fn);
 		}
 		LIST_REMOVE(img, next);
-		free(img);
+		free_image(img);
 	}
 
 	for (unsigned int count = 0; count < ARRAY_SIZE(list); count++) {
@@ -413,7 +417,7 @@  void cleanup_files(struct swupdate_cfg *software) {
 			cleaup_img_entry(img);
 
 			LIST_REMOVE(img, next);
-			free(img);
+			free_image(img);
 		}
 	}
 
diff --git a/include/swupdate.h b/include/swupdate.h
index db9abbf..7de096a 100644
--- a/include/swupdate.h
+++ b/include/swupdate.h
@@ -147,5 +147,6 @@  struct swupdate_cfg {
 off_t extract_sw_description(int fd, const char *descfile, off_t start);
 int cpio_scan(int fd, struct swupdate_cfg *cfg, off_t start);
 struct swupdate_cfg *get_swupdate_cfg(void);
+void free_image(struct img_type *img);
 
 #endif
diff --git a/parser/parser.c b/parser/parser.c
index 06f03b6..e07ed8e 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -225,7 +225,6 @@  static int run_embscript(parsertype p, void *elem, struct img_type *img,
 	if (!exist_field_string(p, elem, "hook"))
 		return 0;
 	embfcn = get_field_string(p, elem, "hook");
-
 	return lua_parser_fn(L, embfcn, img);
 }
 
@@ -302,7 +301,7 @@  static int parse_partitions(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
 			return -ENOMEM;
 		}
 		if (parse_common_attributes(p, elem, partition) < 0) {
-			free(partition);
+			free_image(partition);
 			return -1;
 		}
 		GET_FIELD_STRING(p, elem, "name", partition->volname);
@@ -315,7 +314,7 @@  static int parse_partitions(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
 
 		if (!strlen(partition->volname) || !strlen(partition->device)) {
 			ERROR("Partition incompleted in description file");
-			free(partition);
+			free_image(partition);
 			return -1;
 		}
 
@@ -368,7 +367,7 @@  static int parse_scripts(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
 		}
 
 		if (parse_common_attributes(p, elem, script) < 0) {
-			free(script);
+			free_image(script);
 			return -1;
 		}
 
@@ -440,7 +439,7 @@  static int parse_bootloader(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
 		}
 
 		if (parse_common_attributes(p, elem, script) < 0) {
-			free(script);
+			free_image(script);
 			return -1;
 		}
 
@@ -489,7 +488,7 @@  static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua
 		}
 
 		if (parse_common_attributes(p, elem, image) < 0) {
-			free(image);
+			free_image(image);
 			return -1;
 		}
 
@@ -504,8 +503,7 @@  static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua
 		add_properties(p, elem, image);
 
 		if (run_embscript(p, elem, image, L, swcfg->embscript)) {
-			dict_drop_db(&image->properties);
-			free(image);
+			free_image(image);
 			return -1;
 		}
 
@@ -563,7 +561,7 @@  static int parse_files(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua_
 		}
 
 		if (parse_common_attributes(p, elem, file) < 0) {
-			free(file);
+			free_image(file);
 			return -1;
 		}
 
@@ -574,8 +572,7 @@  static int parse_files(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua_
 		add_properties(p, elem, file);
 
 		if (run_embscript(p, elem, file, L, swcfg->embscript)) {
-			dict_drop_db(&file->properties);
-			free(file);
+			free_image(file);
 			return -1;
 		}