bootspec: Fixup memory leak
authorAdrian Vovk <adrianvovk@gmail.com>
Tue, 1 Oct 2024 20:53:02 +0000 (22:53 +0200)
committerAdrian Vovk <adrianvovk@gmail.com>
Tue, 26 Nov 2024 21:33:10 +0000 (16:33 -0500)
This would previously leak memory: the array was deleted but contents
inside of the array were not

src/shared/bootspec.c
src/shared/bootspec.h

index 584515a29790b1b40a31a5c8857b6068fbcdad0e..49440dded1b50acb4818333f4d4fc54ee019c028 100644 (file)
@@ -44,6 +44,8 @@ static const char* const boot_entry_type_json_table[_BOOT_ENTRY_TYPE_MAX] = {
 
 DEFINE_STRING_TABLE_LOOKUP_TO_STRING(boot_entry_type_json, BootEntryType);
 
+static void boot_entry_addons_done(BootEntryAddons *addons);
+
 static void boot_entry_free(BootEntry *entry) {
         assert(entry);
 
@@ -59,7 +61,7 @@ static void boot_entry_free(BootEntry *entry) {
         free(entry->machine_id);
         free(entry->architecture);
         strv_free(entry->options);
-        free(entry->local_addons.items);
+        boot_entry_addons_done(&entry->local_addons);
         free(entry->kernel);
         free(entry->efi);
         strv_free(entry->initrd);
@@ -426,7 +428,8 @@ void boot_config_free(BootConfig *config) {
         FOREACH_ARRAY(i, config->entries, config->n_entries)
                 boot_entry_free(i);
         free(config->entries);
-        free(config->global_addons.items);
+
+        boot_entry_addons_done(&config->global_addons);
 
         set_free(config->inodes_seen);
 }
index 58c676fbeca874f4e8faf33b9ea9523c2b76c62b..0bb75669ce813ebaaa3f899ae165002004102570 100644 (file)
@@ -31,8 +31,6 @@ typedef struct BootEntryAddons {
         size_t n_items;
 } BootEntryAddons;
 
-BootEntryAddon* boot_entry_addon_free(BootEntryAddon *t);
-
 typedef struct BootEntry {
         BootEntryType type;
         bool reported_by_loader;