Skip to content

Commit ced002d

Browse files
committed
context BUGFIX extension ext instances safe free
1 parent 0f42bd7 commit ced002d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/context.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,8 +1486,9 @@ ly_ctx_is_printed(const struct ly_ctx *ctx)
14861486
LIBYANG_API_DEF void
14871487
ly_ctx_destroy(struct ly_ctx *ctx)
14881488
{
1489-
uint32_t i;
14901489
struct lys_module *mod;
1490+
uint32_t i;
1491+
LY_ARRAY_COUNT_TYPE u;
14911492

14921493
if (!ctx) {
14931494
return;
@@ -1514,9 +1515,15 @@ ly_ctx_destroy(struct ly_ctx *ctx)
15141515
lysc_module_free(ctx, mod->compiled);
15151516
mod->compiled = NULL;
15161517
}
1518+
1519+
/* even compiled ext definitions can have ext instances, free those, too */
1520+
LY_ARRAY_FOR(mod->extensions, u) {
1521+
FREE_ARRAY(ctx, mod->extensions[u].exts, lysc_ext_instance_free);
1522+
mod->extensions[u].exts = NULL;
1523+
}
15171524
}
15181525

1519-
/* free the modules (with compiled extension definitions) */
1526+
/* free the modules */
15201527
for (i = 0; i < ctx->modules.count; ++i) {
15211528
mod = ctx->modules.objs[i];
15221529
lys_module_free(ctx, mod, 0);

0 commit comments

Comments
 (0)