Skip to content

Commit 3ac8be1

Browse files
committed
plugins ext UPDATE remove the need for SM context destroy
1 parent a23d4a7 commit 3ac8be1

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

src/plugins_exts.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,14 @@ lyplg_ext_set_parent_ctx(struct ly_ctx *ctx, const struct ly_ctx *parent_ctx)
761761
} while (c);
762762

763763
if (!ctx->parent_ctx) {
764-
/* remove its shared and private data */
765-
ly_ctx_data_del(ctx);
764+
if (ly_ctx_is_printed(ctx) && ly_ctx_is_printed(parent_ctx)) {
765+
/* completely destroy the printed context, assume it will not be destroyed (in case of schema-mount
766+
* contexts, there is no ext callback for freeing the compiled extension data with the contexts) */
767+
ly_ctx_destroy(ctx);
768+
} else {
769+
/* remove its shared and private data */
770+
ly_ctx_data_del(ctx);
771+
}
766772
} else if (!parent_ctx) {
767773
/* create its shared and private data */
768774
LY_CHECK_RET(ly_ctx_data_add(ctx));

src/plugins_exts/schema_mount.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -533,43 +533,37 @@ lyplg_ext_schema_mount_destroy_shared_contexts(struct lysc_ext_instance *ext)
533533
int r;
534534
uint32_t i;
535535
struct lyplg_ext_sm *sm_data;
536-
ly_bool ctx_is_printed;
537536

538537
LY_CHECK_ARG_RET(NULL, ext, );
539538

539+
if (ly_ctx_is_printed(ext->module->ctx)) {
540+
/* shared contexts were destroyed during ext compilation */
541+
return;
542+
}
543+
540544
sm_data = ext->compiled;
541-
ctx_is_printed = ly_ctx_is_printed(ext->module->ctx);
542545

543-
/* LOCK (dont lock if pctx since its memory is not writable) */
544-
if (!ctx_is_printed) {
545-
if ((r = pthread_mutex_lock(&sm_data->lock))) {
546-
lyplg_ext_compile_log(NULL, ext, LY_LLERR, LY_ESYS, "Mutex lock failed (%s).", strerror(r));
547-
return;
548-
}
546+
/* LOCK */
547+
if ((r = pthread_mutex_lock(&sm_data->lock))) {
548+
lyplg_ext_compile_log(NULL, ext, LY_LLERR, LY_ESYS, "Mutex lock failed (%s).", strerror(r));
549+
return;
549550
}
550551

551552
/* free all the shared schemas of this ext */
552553
for (i = 0; i < sm_data->shared->schema_count; ++i) {
553-
/* ctx can be destroyed whether printed or not */
554554
ly_ctx_destroy(sm_data->shared->schemas[i].ctx);
555-
556-
if (!ctx_is_printed) {
557-
/* these members can be freed only if the context is not printed */
558-
free(sm_data->shared->schemas[i].mount_point);
559-
sm_data->shared->schemas[i].mount_point = NULL;
560-
free(sm_data->shared->schemas[i].content_id);
561-
sm_data->shared->schemas[i].content_id = NULL;
562-
}
555+
free(sm_data->shared->schemas[i].mount_point);
556+
sm_data->shared->schemas[i].mount_point = NULL;
557+
free(sm_data->shared->schemas[i].content_id);
558+
sm_data->shared->schemas[i].content_id = NULL;
563559
}
564560

565-
if (!ctx_is_printed) {
566-
free(sm_data->shared->schemas);
567-
sm_data->shared->schemas = NULL;
568-
sm_data->shared->schema_count = 0;
561+
free(sm_data->shared->schemas);
562+
sm_data->shared->schemas = NULL;
563+
sm_data->shared->schema_count = 0;
569564

570-
/* UNLOCK */
571-
pthread_mutex_unlock(&sm_data->lock);
572-
}
565+
/* UNLOCK */
566+
pthread_mutex_unlock(&sm_data->lock);
573567
}
574568

575569
LIBYANG_API_DEF void

0 commit comments

Comments
 (0)