[Concept,15/17] test: dm: Fix memory leaks in ACPI DP tests

Message ID 20260316183050.3855921-16-sjg@u-boot.org
State New
Headers
Series Add automatic memory-leak detection to U-Boot tests |

Commit Message

Simon Glass March 16, 2026, 6:30 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Fix three memory leaks in the ACPI device property tests:
- free_context() does not free ctx->base, unlike the version in
  acpigen.c
- dm_test_acpi_dp_gpio() does not call free_context()
- dm_test_acpi_dp_copy() does not call free_context()

Fixes: 0e5a0a00d6e4 ("acpi: Support writing Device Properties objects via _DSD")
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 test/dm/acpi_dp.c | 5 +++++
 1 file changed, 5 insertions(+)
  

Patch

diff --git a/test/dm/acpi_dp.c b/test/dm/acpi_dp.c
index 038806004b5..90921329556 100644
--- a/test/dm/acpi_dp.c
+++ b/test/dm/acpi_dp.c
@@ -36,6 +36,7 @@  static int alloc_context(struct acpi_ctx **ctxp)
 
 static void free_context(struct acpi_ctx **ctxp)
 {
+	free((*ctxp)->base);
 	free(*ctxp);
 	*ctxp = NULL;
 }
@@ -419,6 +420,8 @@  static int dm_test_acpi_dp_gpio(struct unit_test_state *uts)
 	ut_asserteq(ZERO_OP, pptr[0x1b]);
 	ut_asserteq(ONE_OP, pptr[0x1c]);
 
+	free_context(&ctx);
+
 	return 0;
 }
 DM_TEST(dm_test_acpi_dp_gpio, 0);
@@ -486,6 +489,8 @@  static int dm_test_acpi_dp_copy(struct unit_test_state *uts)
 	ut_asserteq(STRING_PREFIX, ptr[0x8e]);
 	ut_asserteq_str("sunrise ohoka", (char *)(ptr + 0x8f));
 
+	free_context(&ctx);
+
 	return 0;
 }
 DM_TEST(dm_test_acpi_dp_copy, UTF_SCAN_PDATA | UTF_SCAN_FDT);