mem-leak fix for acpi_thermal_write_trip_points()
Subsystems (2)
PATCH 1/1 mem-leak fix for acpi_thermal_write_trip_points()
There's a memory leak in
drivers/acpi/thermal.c::acpi_thermal_write_trip_points()
found by the Coverity checker as bug #1243
The problem is simply that if the allocation of 'active' fails, then we'll return from the function without freeing the memory previously allocated to 'limit_string'.
One fix would have been the insertion of kfree(limit_string); just before the return_VALUE(-ENOMEM); call, but I chose a different fix. Except for this one return the function only has a single exit point at the end: label, and there it does proper cleanup of everything. So even though setting the return value (the 'count' variable) and jumping there results in a pointless kfree(NULL) call (since 'active' will be NULL), I thought this was a small price to pay for the bennefit of having just a single exit path for the function.
---
drivers/acpi/thermal.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/acpi/thermal.c +4 -2
@@ -942,8 +942,10 @@ acpi_thermal_write_trip_points(struct fimemset (limit_string,0 ,ACPI_THERMAL_MAX_LIMIT_STR_LEN ); active =kmalloc (ACPI_THERMAL_MAX_ACTIVE *sizeof (int ),GFP_KERNEL ); -if (!active) -return_VALUE (-ENOMEM ); +if (!active) { + count = -ENOMEM ; + goto end; + }if (!tz || (count >ACPI_THERMAL_MAX_LIMIT_STR_LEN -1 )) {ACPI_DEBUG_PRINT ((ACPI_DB_ERROR ,"Invalid argument\n" ));