@@ -464,6 +464,24 @@ static void my_dlclose(void *library) {
464
464
#endif
465
465
}
466
466
467
+ static void my_dlclose_no_assert (void *library) {
468
+ #ifdef _WIN32
469
+ FreeLibrary ((HMODULE)library);
470
+ #else
471
+ dlclose (library);
472
+ #endif
473
+ }
474
+
475
+ typedef struct my_dl_wrapper {
476
+ void *handle;
477
+ my_dl_wrapper (void *handle) { this ->handle = handle; }
478
+ ~my_dl_wrapper () { my_dlclose_no_assert (this ->handle ); }
479
+ // prohibit copying to avoid double-close of handle
480
+ my_dl_wrapper (const my_dl_wrapper &) = delete ;
481
+ my_dl_wrapper &operator =(const my_dl_wrapper &) = delete ;
482
+ } my_dl_wrapper;
483
+ std::vector<std::unique_ptr<my_dl_wrapper>> mmd_libs;
484
+
467
485
cl_bool l_load_board_functions (acl_mmd_dispatch_t *mmd_dispatch,
468
486
const char *library_name, void *mmd_library,
469
487
char *error_msg) {
@@ -632,12 +650,14 @@ cl_bool l_load_single_board_library(const char *library_name,
632
650
if (result == CL_FALSE) {
633
651
std::cout << " Error: Could not load board library " << library_name
634
652
<< " due to failure to load symbols\n " ;
653
+ my_dlclose (mmd_library);
635
654
return result;
636
655
}
637
656
}
638
657
++num_boards_found;
639
658
}
640
659
660
+ mmd_libs.push_back (std::make_unique<my_dl_wrapper>(mmd_library));
641
661
return CL_TRUE;
642
662
}
643
663
@@ -1193,6 +1213,7 @@ static acl_mmd_dispatch_t *get_msim_mmd_layer() {
1193
1213
return nullptr ;
1194
1214
}
1195
1215
auto *sym = my_dlsym (mmd_lib, sym_name, &error_msg);
1216
+ mmd_libs.push_back (std::make_unique<my_dl_wrapper>(mmd_lib));
1196
1217
if (!sym) {
1197
1218
std::cout << " Error: Symbol " << sym_name
1198
1219
<< " not found in simulation MMD library " ;
0 commit comments