From 05ae94092e6bf40344a5ffb4dbd58121a853668e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Wed, 20 Nov 2024 18:59:20 +0100 Subject: [PATCH] [COMPBATT] Free device-related memory only if we failed Otherwise, we just inserted in the BatteryList this device, and we will probably crash later when accessing it. --- drivers/bus/acpi/compbatt/comppnp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/bus/acpi/compbatt/comppnp.c b/drivers/bus/acpi/compbatt/comppnp.c index 1083ae7f866..61b87736758 100644 --- a/drivers/bus/acpi/compbatt/comppnp.c +++ b/drivers/bus/acpi/compbatt/comppnp.c @@ -199,8 +199,11 @@ CompBattAddNewBattery(IN PUNICODE_STRING BatteryName, Status); } - /* Free the battery data */ - ExFreePool(BatteryData); + if (!NT_SUCCESS(Status)) + { + /* Free the battery data */ + ExFreePool(BatteryData); + } } else {