[Concept,22/33] upl: Dispose of live trees after use

Message ID 20260416023021.626949-23-sjg@u-boot.org
State New
Headers
Series Fix memory leaks and test pollution in sandbox tests |

Commit Message

Simon Glass April 16, 2026, 2:29 a.m. UTC
  From: Simon Glass <sjg@chromium.org>

do_upl_write() builds a live tree via upl_create_handoff_tree() and
flattens it with oftree_to_fdt(), but never disposes the tree.

Similarly, do_upl_read() calls oftree_from_fdt() and drops the resulting
tree on return. Each invocation of 'upl read'/'upl write' therefore
leaks several kilobytes of ofnode state.

Dispose of both trees once they are no longer needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 cmd/upl.c | 2 ++
 1 file changed, 2 insertions(+)
  

Patch

diff --git a/cmd/upl.c b/cmd/upl.c
index ef2183d8528..c6748fa1f7f 100644
--- a/cmd/upl.c
+++ b/cmd/upl.c
@@ -68,6 +68,7 @@  static int do_upl_write(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	log_debug("Flattening\n");
 	ret = oftree_to_fdt(tree, &buf);
+	oftree_dispose(tree);
 	if (ret) {
 		log_err("Failed to write (err=%dE)\n", ret);
 		return CMD_RET_FAILURE;
@@ -100,6 +101,7 @@  static int do_upl_read(struct cmd_tbl *cmdtp, int flag, int argc,
 	printf("Reading UPL at %lx\n", addr);
 	tree = oftree_from_fdt(map_sysmem(addr, 0));
 	ret = upl_read_handoff(upl, tree);
+	oftree_dispose(tree);
 	if (ret) {
 		log_err("Failed to read (err=%dE)\n", ret);
 		return CMD_RET_FAILURE;