diff --git a/dll/win32/dbghelp/dbghelp.c b/dll/win32/dbghelp/dbghelp.c index c67f973012..71caf8281d 100644 --- a/dll/win32/dbghelp/dbghelp.c +++ b/dll/win32/dbghelp/dbghelp.c @@ -191,6 +191,37 @@ struct cpu* cpu_find(DWORD machine) return NULL; } +static WCHAR *make_default_search_path(void) +{ + WCHAR* search_path; + unsigned size; + unsigned len; + static const WCHAR sym_path[] = {'_','N','T','_','S','Y','M','B','O','L','_','P','A','T','H',0}; + static const WCHAR alt_sym_path[] = {'_','N','T','_','A','L','T','E','R','N','A','T','E','_','S','Y','M','B','O','L','_','P','A','T','H',0}; + + size = 1; + search_path = HeapAlloc(GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR)); + search_path[0] = '.'; + search_path[1] = 0; + + len = GetEnvironmentVariableW(sym_path, NULL, 0); + if (len) + { + search_path = HeapReAlloc(GetProcessHeap(), 0, search_path, (size + 1 + len + 1) * sizeof(WCHAR)); + search_path[size] = ';'; + GetEnvironmentVariableW(sym_path, search_path + size + 1, len); + size += 1 + len; + } + len = GetEnvironmentVariableW(alt_sym_path, NULL, 0); + if (len) + { + search_path = HeapReAlloc(GetProcessHeap(), 0, search_path, (size + 1 + len + 1) * sizeof(WCHAR)); + search_path[size] = ';'; + GetEnvironmentVariableW(alt_sym_path, search_path + size + 1, len); + } + return search_path; +} + /****************************************************************** * SymSetSearchPathW (DBGHELP.@) * @@ -219,12 +250,18 @@ BOOL WINAPI SymSetSearchPath(HANDLE hProcess, PCSTR searchPath) unsigned len; WCHAR* sp; - len = MultiByteToWideChar(CP_ACP, 0, searchPath, -1, NULL, 0); - if ((sp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)))) + if (searchPath) { + len = MultiByteToWideChar(CP_ACP, 0, searchPath, -1, NULL, 0); + sp = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + if (!sp) return FALSE; MultiByteToWideChar(CP_ACP, 0, searchPath, -1, sp, len); + } - ret = SymSetSearchPathW(hProcess, sp); + ret = SymSetSearchPathW(hProcess, sp); + + if (searchPath) + { HeapFree(GetProcessHeap(), 0, sp); } return ret; @@ -448,31 +485,7 @@ BOOL WINAPI SymInitializeW(HANDLE hProcess, PCWSTR UserSearchPath, BOOL fInvadeP } else { - unsigned size; - unsigned len; - static const WCHAR sym_path[] = {'_','N','T','_','S','Y','M','B','O','L','_','P','A','T','H',0}; - static const WCHAR alt_sym_path[] = {'_','N','T','_','A','L','T','E','R','N','A','T','E','_','S','Y','M','B','O','L','_','P','A','T','H',0}; - - pcs->search_path = HeapAlloc(GetProcessHeap(), 0, (len = MAX_PATH) * sizeof(WCHAR)); - while ((size = GetCurrentDirectoryW(len, pcs->search_path)) >= len) - pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (len *= 2) * sizeof(WCHAR)); - pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1) * sizeof(WCHAR)); - - len = GetEnvironmentVariableW(sym_path, NULL, 0); - if (len) - { - pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1 + len + 1) * sizeof(WCHAR)); - pcs->search_path[size] = ';'; - GetEnvironmentVariableW(sym_path, pcs->search_path + size + 1, len); - size += 1 + len; - } - len = GetEnvironmentVariableW(alt_sym_path, NULL, 0); - if (len) - { - pcs->search_path = HeapReAlloc(GetProcessHeap(), 0, pcs->search_path, (size + 1 + len + 1) * sizeof(WCHAR)); - pcs->search_path[size] = ';'; - GetEnvironmentVariableW(alt_sym_path, pcs->search_path + size + 1, len); - } + pcs->search_path = make_default_search_path(); } pcs->lmodules = NULL;