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; ...@@ -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_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; 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; 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 struct vector
{ {
......
...@@ -1068,7 +1068,6 @@ BOOL module_remove(struct process* pcs, struct module* module) ...@@ -1068,7 +1068,6 @@ BOOL module_remove(struct process* pcs, struct module* module)
hash_table_destroy(&module->ht_types); hash_table_destroy(&module->ht_types);
HeapFree(GetProcessHeap(), 0, module->sources); HeapFree(GetProcessHeap(), 0, module->sources);
HeapFree(GetProcessHeap(), 0, module->addr_sorttab); HeapFree(GetProcessHeap(), 0, module->addr_sorttab);
HeapFree(GetProcessHeap(), 0, module->real_path);
pool_destroy(&module->pool); pool_destroy(&module->pool);
/* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here /* native dbghelp doesn't invoke registered callback(,CBA_SYMBOLS_UNLOADED,) here
* so do we * so do we
......
...@@ -760,13 +760,10 @@ struct builtin_search ...@@ -760,13 +760,10 @@ struct builtin_search
static BOOL search_builtin_pe(void *param, HANDLE handle, const WCHAR *path) static BOOL search_builtin_pe(void *param, HANDLE handle, const WCHAR *path)
{ {
struct builtin_search *search = param; struct builtin_search *search = param;
size_t size;
if (!pe_map_file(handle, &search->fmap, DMT_PE)) return FALSE; if (!pe_map_file(handle, &search->fmap, DMT_PE)) return FALSE;
size = (lstrlenW(path) + 1) * sizeof(WCHAR); search->path = wcsdup(path);
if ((search->path = heap_alloc(size)))
memcpy(search->path, path, size);
return TRUE; return TRUE;
} }
...@@ -818,8 +815,9 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name, ...@@ -818,8 +815,9 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
} }
if (name) lstrcpyW(loaded_name, 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); modfmt->u.pe_info = (struct pe_module_info*)(modfmt + 1);
if (pe_map_file(hFile, &modfmt->u.pe_info->fmap, DMT_PE)) 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, ...@@ -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); modfmt->u.pe_info->fmap.u.pe.file_header.Machine);
if (module) if (module)
{ {
module->real_path = real_path; module->real_path = real_path ? pool_wcsdup(&module->pool, real_path) : NULL;
modfmt->module = module; modfmt->module = module;
modfmt->remove = pe_module_remove; modfmt->remove = pe_module_remove;
modfmt->loc_compute = NULL; modfmt->loc_compute = NULL;
...@@ -851,14 +849,14 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name, ...@@ -851,14 +849,14 @@ struct module* pe_load_native_module(struct process* pcs, const WCHAR* name,
else else
{ {
ERR("could not load the module '%s'\n", debugstr_w(loaded_name)); ERR("could not load the module '%s'\n", debugstr_w(loaded_name));
heap_free(real_path);
image_unmap_file(&modfmt->u.pe_info->fmap); image_unmap_file(&modfmt->u.pe_info->fmap);
} }
} }
if (!module) HeapFree(GetProcessHeap(), 0, modfmt); if (!module) HeapFree(GetProcessHeap(), 0, modfmt);
}
if (opened) CloseHandle(hFile); if (opened) CloseHandle(hFile);
free(real_path);
return module; return module;
} }
......
...@@ -55,6 +55,13 @@ char* pool_strdup(struct pool* pool, const char* str) ...@@ -55,6 +55,13 @@ char* pool_strdup(struct pool* pool, const char* str)
return ret; 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) void vector_init(struct vector* v, unsigned esz, unsigned bucket_sz)
{ {
v->buckets = NULL; 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