(un)fortunately, this sheds some light on existing discrepancy in memory management
real_path is either allocated by crt (wcsdup in pe_load_native_module) or heap (in search_dll_path), and freed from heap (pe_load_native_module and module_remove)
so I'd rather keep this rule of thumb: - long lived allocation: use heap (and even better use module's heap, so we don't have to free them one by one) - short live allocation (inside 1 function): use crt (btw, it looks "interesting" that none of the analysers caught this before)
so I'd rather go for replacing the wcsdup with a global heap allocation in pe_load_native_module, and heap_free in what you're proposing in your patch