[Git][ghc/ghc][wip/backports-9.14] rts/linker/PEi386: Copy strings before they are inserted into LoadedDllCache....
Zubin pushed to branch wip/backports-9.14 at Glasgow Haskell Compiler / GHC Commits: b806c396 by Zubin Duggal at 2025-11-27T14:14:21+05:30 rts/linker/PEi386: Copy strings before they are inserted into LoadedDllCache. The original strings are temporary and might be freed at an arbitrary point. Fixes #26613 (cherry picked from commit f23c335b2347d586696a3a77f9dfa95ef6272c0e) - - - - - 1 changed file: - rts/linker/PEi386.c Changes: ===================================== rts/linker/PEi386.c ===================================== @@ -552,7 +552,12 @@ static int compare_path(StgWord key1, StgWord key2) static void addLoadedDll(LoadedDllCache *cache, const pathchar *dll_name, HINSTANCE instance) { - insertHashTable_(cache->hash, (StgWord) dll_name, instance, hash_path); + // dll_name might be deallocated, we need to copy it to have a stable reference to the contents + // See #26613 + int size = sizeof(pathchar) * wcslen(dll_name) + 1; + pathchar* dll_name_copy = stgMallocBytes(size, "addLoadedDll"); + wcsncpy(dll_name_copy, dll_name, size); + insertHashTable_(cache->hash, (StgWord) dll_name_copy, instance, hash_path); } static HINSTANCE isDllLoaded(const LoadedDllCache *cache, const pathchar *dll_name) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b806c396a8033ec80c9714cf79a4a7a5... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b806c396a8033ec80c9714cf79a4a7a5... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Zubin (@wz1000)