Skip to contentSkip to conversation

ACPI: custom_method: fix a possible memory leak

PATCH In review shiqiang.deng 2 participants 2 messages Nov 11, 2023 – Nov 12, 2023 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI: custom_method: fix a possible memory leak

In the cm_write() function, memory is allocated, and at the end of the function when uncopied_bytes is 0, the memory is freed. If uncopied_bytes is not equal to 0, a memory leak occurs.

---
 drivers/acpi/custom_method.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/acpi/custom_method.c +3 -0
index d39a9b474727..5103c7c3a6ce 100644
@@ -77,6 +77,9 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
 		if (ACPI_FAILURE(status))
 			return -EINVAL;
 		add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
+	} else {
+		kfree(buf);
+		buf = NULL;
 	}
 
 	return count;
Signature · 1 line
2.30.0
#1 lore raw
Quoted 16 lines · shiqiang.deng

In the cm_write() function, memory is allocated, and at the end of the function when uncopied_bytes is 0, the memory is freed. If uncopied_bytes is not equal to 0, a memory leak occurs.

---
 drivers/acpi/custom_method.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/acpi/custom_method.c +0 -0
index d39a9b474727..5103c7c3a6ce 100644

drivers/acpi/custom_method.c static ssize_t cm_write(struct file *file, const char __user *user_buf,

Quoted 10 lines
drivers/acpi/custom_method.c +3 -1
@@ -77,6 +77,9 @@ static ssize_t cm_write(struct file *file, const char __user *user_buf,
                if (ACPI_FAILURE(status))
                        return -EINVAL;
                add_taint(TAINT_OVERRIDDEN_ACPI_TABLE, LOCKDEP_NOW_UNRELIABLE);
+       } else {
+               kfree(buf);
+               buf = NULL;
        }
 
        return count;
--

That was discussed in the past and I still would rather drop this I/F completely instead of patching it for minor issues.