Commit 00df1bea authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

dbghelp: Allocate real_path with the CRT and copy it to the module heap.

Fixes both a memory leak and an alloc/free mismatch, and the module heap is the most appropriate place to hold the variable long-term.
parent 39cc4fcc
......@@ -44,6 +44,7 @@ void pool_destroy(struct pool* a) DECLSPEC_HIDDEN;
void* pool_alloc(struct pool* a, size_t len) __WINE_ALLOC_SIZE(2) __WINE_MALLOC DECLSPEC_HIDDEN;
void* pool_realloc(struct pool* a, void* ptr, size_t len) __WINE_ALLOC_SIZE(3) DECLSPEC_HIDDEN;
char* pool_strdup(struct pool* a, const char* str) __WINE_MALLOC DECLSPEC_HIDDEN;
WCHAR* pool_wcsdup(struct pool* a, const WCHAR* str) __WINE_MALLOC DECLSPEC_HIDDEN;
struct vector
{
......
......@@ -1068,7 +1068,6 @@ BOOL module_remove(struct process* pcs, struct module* module)
hash_table_destroy(&module->ht_types);
HeapFree(GetProcessHeap(), 0, module->sources);
HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
HeapFree(GetProcessHeap(), 0, module->real_path);
pool_destroy(&module->pool);
/* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
* so do we
......
......@@ -760,13 +760,10 @@ struct builtin_search
static BOOL search_builtin_pe(void *param, HANDLE handle, const WCHAR *path)
{
struct builtin_search *search = param;
size_t size;
if (!pe_map_file(handle, &search->fmap, DMT_PE)) return FALSE;
size = (lstrlenW(path) + 1) * sizeof(WCHAR);
if ((search->path = heap_alloc(size)))
memcpy(search->path, path, size);
search->path = wcsdup(path);
return TRUE;
}
......@@ -818,8 +815,9 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
}
if (name) lstrcpyW(loaded_name, name);
}
if (!(modfmt = HeapAlloc(GetProcessHeap(), 0, sizeof(struct module_format) + sizeof(struct pe_module_info))))
return NULL;
if ((modfmt = HeapAlloc(GetProcessHeap(), 0, sizeof(struct module_format) + sizeof(struct pe_module_info))))
{
modfmt->u.pe_info = (struct pe_module_info*)(modfmt + 1);
if (pe_map_file(hFile, &modfmt->u.pe_info->fmap, DMT_PE))
{
......@@ -841,7 +839,7 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
modfmt->u.pe_info->fmap.u.pe.file_header.Machine);
if (module)
{
module->real_path = real_path;
module->real_path = real_path ? pool_wcsdup(&module->pool, real_path) : NULL;
modfmt->module = module;
modfmt->remove = pe_module_remove;
modfmt->loc_compute = NULL;
......@@ -851,14 +849,14 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
else
{
ERR("could not load the module '%s'\n", debugstr_w(loaded_name));
heap_free(real_path);
image_unmap_file(&modfmt->u.pe_info->fmap);
}
}
if (!module) HeapFree(GetProcessHeap(), 0, modfmt);
}
if (opened) CloseHandle(hFile);
free(real_path);
return module;
}
......
......@@ -55,6 +55,13 @@ char* pool_strdup(struct pool* pool, const char* str)
return ret;
}
WCHAR* pool_wcsdup(struct pool* pool, const WCHAR* str)
{
WCHAR* ret;
if ((ret = pool_alloc(pool, (wcslen(str) + 1) * sizeof(WCHAR)))) wcscpy(ret, str);
return ret;
}
void vector_init(struct vector* v, unsigned esz, unsigned bucket_sz)
{
v->buckets = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment