[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: 85e8147d by Zubin Duggal at 2025-11-28T14:00:24+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 5072da477b8ec883aea4b9ea27763fcc1971af1a) - - - - - 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 + size_t size = wcslen(dll_name) + 1; + pathchar* dll_name_copy = stgMallocBytes(size * sizeof(pathchar), "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/85e8147dd7893db46db1868d65f4cffe... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/85e8147dd7893db46db1868d65f4cffe... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Zubin (@wz1000)