lib: Prevent memory leak on error path

Free the tree before returning to prevent a leak.

Change-Id: I1132c0e7404eec1af3adc19a83257f28563f8a58
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Found-by: Coverity CID 1401799
Reviewed-on: https://review.coreboot.org/c/coreboot/+/33298
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Jacob Garber 2019-06-07 10:28:54 -06:00 committed by Patrick Georgi
parent 176670e31a
commit 698d83a7c8
1 changed files with 2 additions and 0 deletions

View File

@ -259,11 +259,13 @@ struct device_tree *fdt_unflatten(const void *blob)
if (magic != FDT_HEADER_MAGIC) {
printk(BIOS_DEBUG, "Invalid device tree magic %#.8x!\n", magic);
free(tree);
return NULL;
}
if (last_comp_version > FDT_SUPPORTED_VERSION) {
printk(BIOS_DEBUG, "Unsupported device tree version %u(>=%u)\n",
version, last_comp_version);
free(tree);
return NULL;
}
if (version > FDT_SUPPORTED_VERSION)