On Sat Jun 10 19:22:55 2023 +0000, eric pouech wrote:
(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
Interesting. That's definitely a problem.
The downside to allocating real_path with `HeapAlloc(GetProcessHeap(), ...)` is that we'd have to reimplement strdup. Are you sure that's better than using the CRT in this case?