Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions loader/icd.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@ void khrIcdVendorAdd(const char *libraryName)
}
}

void khrIcdVendorCleanup() {
KHRicdVendor* nextVendor = NULL;
while (khrIcdVendors) {
nextVendor = khrIcdVendors->next;
free(khrIcdVendors);
khrIcdVendors = nextVendor;
}
}

#if defined(CL_ENABLE_LAYERS)
void khrIcdLayerAdd(const char *libraryName)
{
Expand Down Expand Up @@ -345,6 +354,15 @@ void khrIcdLayerAdd(const char *libraryName)
free(layer);
}
}

void khrIcdLayerCleanup() {
struct KHRLayer* nextLayer = NULL;
while (khrFirstLayer) {
nextLayer = khrFirstLayer->next;
free(khrFirstLayer);
khrFirstLayer = nextLayer;
}
}
#endif // defined(CL_ENABLE_LAYERS)

// Get next file or dirname given a string list or registry key path.
Expand Down
6 changes: 6 additions & 0 deletions loader/icd.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,18 @@ void khrIcdVendorsEnumerateEnv(void);
// add a vendor's implementation to the list of libraries
void khrIcdVendorAdd(const char *libraryName);

// cleanup a list of vendor icds
void khrIcdVendorCleanup();

// read layers from environment variables
void khrIcdLayersEnumerateEnv(void);

// add a layer to the layer chain
void khrIcdLayerAdd(const char *libraryName);

// cleanup a layer chain
void khrIcdLayerCleanup();

// dynamically load a library. returns NULL on failure
// n.b, this call is OS-specific
void *khrIcdOsLibraryLoad(const char *libraryName);
Expand Down
5 changes: 5 additions & 0 deletions loader/linux/icd_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,8 @@ void khrIcdOsLibraryUnload(void *library)
{
dlclose(library);
}

void __attribute__((destructor)) khrIcdGlobalDestructor() {
khrIcdVendorCleanup();
khrIcdLayerCleanup();
}
8 changes: 8 additions & 0 deletions loader/windows/icd_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,11 @@ void khrIcdOsLibraryUnload(void *library)
{
FreeLibrary( (HMODULE)library);
}

BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
if (fdwReason == DLL_PROCESS_DETACH) {
khrIcdVendorCleanup();
khrIcdLayerCleanup();
}
return TRUE;
}