@@ -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
575569LIBYANG_API_DEF void
0 commit comments