From ab76b2dd926cd181838b555ef4e25712539aeabc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= <lazzer@gmail.com>
Date: Tue, 24 Feb 2026 16:45:35 +0100
Subject: [PATCH 10/10] Fix sr_lyd_new_path() reporting stale libyang errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Wires

Signed-off-by: Mattias Walström <lazzer@gmail.com>
---
 src/ly_wrap.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/ly_wrap.c b/src/ly_wrap.c
index 340b8b2a..465580e0 100644
--- a/src/ly_wrap.c
+++ b/src/ly_wrap.c
@@ -610,6 +610,10 @@ sr_lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *p
 {
     sr_error_info_t *err_info = NULL;
     uint32_t temp_lo = LY_LOSTORE;
+    const struct ly_ctx *err_ctx = ctx ? ctx : LYD_CTX(parent);
+
+    /* clear any stale errors so sr_errinfo_new_ly() only finds fresh ones */
+    ly_err_clean((struct ly_ctx *)err_ctx, NULL);
 
     ly_temp_log_options(&temp_lo);
 
-- 
2.43.0

