diff --git a/offload/plugins-nextgen/common/include/PluginInterface.h b/offload/plugins-nextgen/common/include/PluginInterface.h index fbc798faec24b..3c03116550636 100644 --- a/offload/plugins-nextgen/common/include/PluginInterface.h +++ b/offload/plugins-nextgen/common/include/PluginInterface.h @@ -1198,6 +1198,8 @@ struct GenericPluginTy { return reinterpret_cast(Allocator.Allocate(sizeof(Ty), alignof(Ty))); } + template void free(Ty *Mem) { Allocator.Deallocate(Mem); } + /// Get the reference to the global handler of this plugin. GenericGlobalHandlerTy &getGlobalHandler() { assert(GlobalHandler && "Global handler not initialized"); diff --git a/offload/plugins-nextgen/host/src/rtl.cpp b/offload/plugins-nextgen/host/src/rtl.cpp index a35910aece986..d950572265b4c 100644 --- a/offload/plugins-nextgen/host/src/rtl.cpp +++ b/offload/plugins-nextgen/host/src/rtl.cpp @@ -151,7 +151,12 @@ struct GenELF64DeviceTy : public GenericDeviceTy { /// /// TODO: This currently does nothing, and should be implemented as part of /// broader memory handling logic for this plugin - Error unloadBinaryImpl(DeviceImageTy *) override { return Plugin::success(); } + Error unloadBinaryImpl(DeviceImageTy *Image) override { + auto Elf = reinterpret_cast(Image); + DynamicLibrary::closeLibrary(Elf->getDynamicLibrary()); + Plugin.free(Elf); + return Plugin::success(); + } /// Deinitialize the device, which is a no-op Error deinitImpl() override { return Plugin::success(); } @@ -212,8 +217,7 @@ struct GenELF64DeviceTy : public GenericDeviceTy { // Load the temporary file as a dynamic library. std::string ErrMsg; - DynamicLibrary DynLib = - DynamicLibrary::getPermanentLibrary(TmpFileName, &ErrMsg); + DynamicLibrary DynLib = DynamicLibrary::getLibrary(TmpFileName, &ErrMsg); // Check if the loaded library is valid. if (!DynLib.isValid())