From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/dbghelp/dbghelp_private.h | 5 +++-- dlls/dbghelp/dwarf.c | 6 +++++- dlls/dbghelp/storage.c | 5 +++++ dlls/dbghelp/type.c | 13 +++++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h index acba5faca37..4f0e2c0edd5 100644 --- a/dlls/dbghelp/dbghelp_private.h +++ b/dlls/dbghelp/dbghelp_private.h @@ -41,8 +41,9 @@ struct pool /* poor's man */
void pool_init(struct pool* a, size_t arena_size); void pool_destroy(struct pool* a); -void* pool_alloc(struct pool* a, size_t len) __WINE_ALLOC_SIZE(2) __WINE_MALLOC; -void* pool_realloc(struct pool* a, void* ptr, size_t len) __WINE_ALLOC_SIZE(3); +void pool_free(struct pool* pool, void* ptr); +void* pool_alloc(struct pool* a, size_t len) __WINE_ALLOC_SIZE(2) __WINE_DEALLOC(pool_free, 2) __WINE_MALLOC; +void* pool_realloc(struct pool* a, void* ptr, size_t len) __WINE_ALLOC_SIZE(3) __WINE_DEALLOC(pool_free, 2); char* pool_strdup(struct pool* a, const char* str) __WINE_MALLOC; WCHAR* pool_wcsdup(struct pool* a, const WCHAR* str) __WINE_MALLOC;
diff --git a/dlls/dbghelp/dwarf.c b/dlls/dbghelp/dwarf.c index 332c3da1059..fda53099519 100644 --- a/dlls/dbghelp/dwarf.c +++ b/dlls/dbghelp/dwarf.c @@ -1311,7 +1311,11 @@ static struct addr_range* dwarf2_get_ranges(const dwarf2_debug_info_t* di, unsig
if (nr == 0) return NULL; ranges = malloc(nr * sizeof(ranges[0])); - if (!ranges || !dwarf2_fill_ranges(di, ranges, nr)) return NULL; + if (!ranges || !dwarf2_fill_ranges(di, ranges, nr)) + { + free(ranges); + return NULL; + } *num_ranges = nr; return ranges; } diff --git a/dlls/dbghelp/storage.c b/dlls/dbghelp/storage.c index 038b625cf1c..f687b352d8a 100644 --- a/dlls/dbghelp/storage.c +++ b/dlls/dbghelp/storage.c @@ -48,6 +48,11 @@ void* pool_realloc(struct pool* pool, void* ptr, size_t len) return ptr ? HeapReAlloc(pool->heap, 0, ptr, len) : pool_alloc(pool, len); }
+void pool_free(struct pool* pool, void* ptr) +{ + HeapFree(pool->heap, 0, ptr); +} + char* pool_strdup(struct pool* pool, const char* str) { char* ret; diff --git a/dlls/dbghelp/type.c b/dlls/dbghelp/type.c index 703555a1ba0..2af62dae0b0 100644 --- a/dlls/dbghelp/type.c +++ b/dlls/dbghelp/type.c @@ -371,7 +371,12 @@ BOOL symt_add_enum_element(struct module* module, struct symt_enum* enum_type, V_I4(&e->u.value) = value;
p = vector_add(&enum_type->vchildren, &module->pool); - if (!p) return FALSE; /* FIXME we leak e */ + if (!p) + { + pool_free(&module->pool, e); + return FALSE; + } + *p = &e->symt;
return TRUE; @@ -424,7 +429,11 @@ BOOL symt_add_function_signature_parameter(struct module* module, arg->symt.tag = SymTagFunctionArgType; arg->arg_type = param; p = vector_add(&sig_type->vchildren, &module->pool); - if (!p) return FALSE; /* FIXME we leak arg */ + if (!p) + { + pool_free(&module->pool, arg); + return FALSE; + } *p = &arg->symt;
return TRUE;
the idea behind pool is that it holds all bits relevant to a module (there's a different pool for each module)
if the allocation for a pool fails, we're in deep trouble anyway (and actually keeping a partially loaded module can generate many other failures)
so I don't feel like a good idea to introduce pool_free; if something has to be done, better ensure that the whole module loading fails in OOM conditions
This merge request was closed by Zhiyi Zhang.