Module: wine Branch: master Commit: 76e8b504c11790ecf2873644f8eb04e6f637ab27 URL: http://source.winehq.org/git/wine.git/?a=commit;h=76e8b504c11790ecf2873644f8...
Author: Eric Pouech eric.pouech@wanadoo.fr Date: Sun Nov 5 17:51:35 2006 +0100
dbghelp: Fixed memory leak in source string handling.
---
dlls/dbghelp/source.c | 33 ++++++++++++++++----------------- 1 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/dlls/dbghelp/source.c b/dlls/dbghelp/source.c index 5842a3f..d9fb076 100644 --- a/dlls/dbghelp/source.c +++ b/dlls/dbghelp/source.c @@ -56,7 +56,6 @@ static unsigned source_find(const struct */ unsigned source_new(struct module* module, const char* base, const char* name) { - int len; unsigned ret; const char* full; char* tmp = NULL; @@ -75,24 +74,24 @@ unsigned source_new(struct module* modul if (tmp[bsz - 1] != '/') tmp[bsz++] = '/'; strcpy(&tmp[bsz], name); } - if (module->sources && (ret = source_find(module, full)) != (unsigned)-1) - return ret; - - len = strlen(full) + 1; - if (module->sources_used + len + 1 > module->sources_alloc) + if (!module->sources || (ret = source_find(module, full)) == (unsigned)-1) { - /* Alloc by block of 256 bytes */ - module->sources_alloc = (module->sources_used + len + 1 + 255) & ~255; - if (!module->sources) - module->sources = HeapAlloc(GetProcessHeap(), 0, module->sources_alloc); - else - module->sources = HeapReAlloc(GetProcessHeap(), 0, module->sources, - module->sources_alloc); + int len = strlen(full) + 1; + if (module->sources_used + len + 1 > module->sources_alloc) + { + /* Alloc by block of 256 bytes */ + module->sources_alloc = (module->sources_used + len + 1 + 255) & ~255; + if (!module->sources) + module->sources = HeapAlloc(GetProcessHeap(), 0, module->sources_alloc); + else + module->sources = HeapReAlloc(GetProcessHeap(), 0, module->sources, + module->sources_alloc); + } + ret = module->sources_used; + memcpy(module->sources + module->sources_used, full, len); + module->sources_used += len; + module->sources[module->sources_used] = '\0'; } - ret = module->sources_used; - strcpy(module->sources + module->sources_used, full); - module->sources_used += len; - module->sources[module->sources_used] = '\0'; HeapFree(GetProcessHeap(), 0, tmp); return ret; }