[PATCH] [DbgHelp]: memory leak
Eric Pouech
eric.pouech at wanadoo.fr
Sun Nov 5 10:51:35 CST 2006
- fixed memory leak in source string handling
A+
---
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 0789f3d..fd0a9a8 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;
}
More information about the wine-patches
mailing list