Skip to content

Commit e79bc43

Browse files
committed
tree schema BUGFIX avoid creating contexts that need to be freed
1 parent 52e074e commit e79bc43

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

src/ly_common.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author Michal Vasko <[email protected]>
55
* @brief common internal definitions for libyang
66
*
7-
* Copyright (c) 2015 - 2024 CESNET, z.s.p.o.
7+
* Copyright (c) 2015 - 2025 CESNET, z.s.p.o.
88
*
99
* This source code is licensed under BSD 3-Clause License (the "License").
1010
* You may not use this file except in compliance with the License.
@@ -680,4 +680,13 @@ LY_ERR ly_munmap(void *addr, size_t length);
680680
*/
681681
LY_ERR ly_strcat(char **dest, const char *format, ...) _FORMAT_PRINTF(2, 3);
682682

683+
/**
684+
* @brief Get schema (context) for a mount point.
685+
*
686+
* @param[in] ext Compiled extension instance where the context is also stored.
687+
* @param[out] ext_ctx Schema to use for parsing the data.
688+
* @return LY_ERR value.
689+
*/
690+
LY_ERR lyplg_ext_schema_mount_get_ctx(struct lysc_ext_instance *ext, const struct ly_ctx **ext_ctx);
691+
683692
#endif /* LY_COMMON_H_ */

src/plugins_exts/schema_mount.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,8 @@ schema_mount_get_ctx_inline(struct lysc_ext_instance *ext, const struct lyd_node
624624
return rc;
625625
}
626626

627-
/**
628-
* @brief Get schema (context) for a mount point.
629-
*
630-
* @param[in] ext Compiled extension instance.
631-
* @param[out] ext_ctx Schema to use for parsing the data.
632-
* @return LY_ERR value.
633-
*/
634-
static LY_ERR
635-
schema_mount_get_ctx(struct lysc_ext_instance *ext, const struct ly_ctx **ext_ctx)
627+
LY_ERR
628+
lyplg_ext_schema_mount_get_ctx(struct lysc_ext_instance *ext, const struct ly_ctx **ext_ctx)
636629
{
637630
LY_ERR ret = LY_SUCCESS, r;
638631
struct lyd_node *iter, *ext_data = NULL;
@@ -693,7 +686,7 @@ schema_mount_snode(struct lysc_ext_instance *ext, const struct lyd_node *parent,
693686
const struct ly_ctx *ext_ctx = NULL;
694687

695688
/* get context based on ietf-yang-library data */
696-
if ((r = schema_mount_get_ctx(ext, &ext_ctx))) {
689+
if ((r = lyplg_ext_schema_mount_get_ctx(ext, &ext_ctx))) {
697690
return r;
698691
}
699692

src/tree_schema.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ lys_getnext_(const struct lysc_node *last, const struct lysc_node *parent, const
168168
const struct lysc_node *next = NULL;
169169
ly_bool action_flag = 0, notif_flag = 0, sm_flag = options & LYS_GETNEXT_WITHSCHEMAMOUNT ? 0 : 1;
170170
LY_ARRAY_COUNT_TYPE u;
171-
struct ly_ctx *sm_ctx = NULL;
171+
const struct ly_ctx *sm_ctx = NULL;
172172
const struct lys_module *mod;
173173
uint32_t idx;
174174

@@ -259,7 +259,7 @@ lys_getnext_(const struct lysc_node *last, const struct lysc_node *parent, const
259259
LY_ARRAY_FOR(parent->exts, u) {
260260
if (!strcmp(parent->exts[u].def->name, "mount-point") &&
261261
!strcmp(parent->exts[u].def->module->name, "ietf-yang-schema-mount")) {
262-
lyplg_ext_schema_mount_create_context(&parent->exts[u], &sm_ctx);
262+
lyplg_ext_schema_mount_get_ctx(&parent->exts[u], &sm_ctx);
263263
if (sm_ctx) {
264264
/* some usable context created */
265265
break;
@@ -276,10 +276,6 @@ lys_getnext_(const struct lysc_node *last, const struct lysc_node *parent, const
276276

277277
next = lys_getnext(NULL, NULL, mod->compiled, options & ~LYS_GETNEXT_WITHSCHEMAMOUNT);
278278
}
279-
if (!next) {
280-
/* no nodes found */
281-
ly_ctx_destroy(sm_ctx);
282-
}
283279
}
284280
}
285281
} else {

0 commit comments

Comments
 (0)