diff mbox series

[firmware-utils,v1,01/10] tplink-safeloader: stricter free_image_partition()

Message ID ad13cbf655f1fdd1e9e704bf2ab1491a7ad9b082.1675461748.git.sander@svanheule.net
State Accepted
Delegated to: Sander Vanheule
Headers show
Series Refactor image ingestion to support new formats | expand

Commit Message

Sander Vanheule Feb. 3, 2023, 10:03 p.m. UTC
Instead of only free()-ing the allocated data block, also clear the name
and size of a payload entry to indicate that it's become invalid.

Signed-off-by: Sander Vanheule <sander@svanheule.net>
---
 src/tplink-safeloader.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/src/tplink-safeloader.c b/src/tplink-safeloader.c
index d9e16058883c..6c4689c2f67c 100644
--- a/src/tplink-safeloader.c
+++ b/src/tplink-safeloader.c
@@ -3156,8 +3156,15 @@  static void set_partition_names(struct device_info *info)
 }
 
 /** Frees an image partition */
-static void free_image_partition(struct image_partition_entry entry) {
-	free(entry.data);
+static void free_image_partition(struct image_partition_entry *entry)
+{
+	void *data = entry->data;
+
+	entry->name = NULL;
+	entry->size = 0;
+	entry->data = NULL;
+
+	free(data);
 }
 
 static time_t source_date_epoch = -1;
@@ -3598,7 +3605,7 @@  static void build_image(const char *output,
 	free(image);
 
 	for (i = 0; parts[i].name; i++)
-		free_image_partition(parts[i]);
+		free_image_partition(&parts[i]);
 }
 
 /** Usage output */