tplink-safeloader: stricter free_image_partition()
authorSander Vanheule <sander@svanheule.net>
Fri, 3 Feb 2023 22:03:15 +0000 (23:03 +0100)
committerSander Vanheule <sander@svanheule.net>
Sun, 12 Mar 2023 12:35:51 +0000 (13:35 +0100)
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

index d9e16058883cea37e43175c18bf5b62f94c13563..6c4689c2f67c8b1804c7f0054736aa761eedc68d 100644 (file)
@@ -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 */