Commit bc7d7fd83d for frr

commit bc7d7fd83da2bbd375e588c9a42ce0d4e05a9872
Author: Philippe Guibert <philippe.guibert@6wind.com>
Date:   Thu Nov 12 17:47:36 2026 +0100

    mgmtd: fix memory leak when dumping a datastore to the vty

    Each 'show mgmt datastore-contents' command displayed on the vty leaks
    the printed datastore. In a topotest compiled with address sanitizer,
    where 'show mgmt datastore-contents candidate json' and 'show mgmt
    datastore-contents running json' were run 8 times each, by support
    bundles, mgmtd reports the leak at exit:

    > ==1274020==ERROR: LeakSanitizer: detected memory leaks
    >
    > Direct leak of 65536 byte(s) in 16 object(s) allocated from:
    >     #0 0x7e09cf4fc778 in realloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:85
    >     #1 0x7e09ceace340 in ly_realloc (/lib/x86_64-linux-gnu/libyang.so.2+0xf340)
    >
    > SUMMARY: AddressSanitizer: 65536 byte(s) leaked in 16 allocation(s).

    When no file is given, mgmt_ds_dump_tree() prints the datastore in a
    buffer allocated by libyang with ly_out_new_memory(). ly_out_free() is
    called with destroy set to 0, so this buffer is never freed. Setting
    destroy to 1 is not an option, as it would also close the file given by
    the caller, which closes it itself.

    Fix this by freeing the buffer after ly_out_free().

    Fixes: 1c84efe4fa85 ("mgmtd: Bringup MGMTD daemon and datastore module support")
    Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>

diff --git a/mgmtd/mgmt_ds.c b/mgmtd/mgmt_ds.c
index ec1aba361c..901f952e92 100644
--- a/mgmtd/mgmt_ds.c
+++ b/mgmtd/mgmt_ds.c
@@ -586,6 +586,7 @@ void mgmt_ds_dump_tree(struct vty *vty, struct mgmt_ds_ctx *ds_ctx,
 		vty_out(vty, "%s\n", str);

 	ly_out_free(out, NULL, 0);
+	free(str);
 }

 void mgmt_ds_status_write_one(struct vty *vty, struct mgmt_ds_ctx *ds_ctx)