diff --git a/common/src/option.c b/common/src/option.c index a0de814b..a8d2ebeb 100644 --- a/common/src/option.c +++ b/common/src/option.c @@ -131,16 +131,16 @@ bool option_register(struct Option options[]) for(int i = 0; options[i].type != OPTION_TYPE_NONE; ++i) ++new; - state.options = realloc( + void * tmp = realloc( state.options, sizeof(*state.options) * (state.oCount + new) ); - - if (!state.options) + if (!tmp) { DEBUG_ERROR("out of memory"); return false; } + state.options = tmp; for(int i = 0; options[i].type != OPTION_TYPE_NONE; ++i) { @@ -229,15 +229,16 @@ bool option_register(struct Option options[]) continue; found = true; - group->options = realloc( + void * tmp = realloc( group->options, sizeof(*group->options) * (group->count + 1) ); - if (!group->options) + if (!tmp) { DEBUG_ERROR("out of memory"); return false; } + group->options = tmp; group->options[group->count] = o; int len = strlen(o->name); @@ -250,15 +251,16 @@ bool option_register(struct Option options[]) if (!found) { - state.groups = realloc( + void * new = realloc( state.groups, sizeof(*state.groups) * (state.gCount + 1) ); - if (!state.groups) + if (!new) { DEBUG_ERROR("out of memory"); return false; } + state.groups = new; struct OptionGroup * group = &state.groups[state.gCount]; ++state.gCount; diff --git a/common/src/platform/linux/crash.c b/common/src/platform/linux/crash.c index 1c6bc940..4ef79328 100644 --- a/common/src/platform/linux/crash.c +++ b/common/src/platform/linux/crash.c @@ -164,7 +164,14 @@ static int dl_iterate_phdr_callback(struct dl_phdr_info * info, size_t size, voi ttl += hdr.p_memsz; } - crash.ranges = realloc(crash.ranges, sizeof(*crash.ranges) * (crash.rangeCount + 1)); + void * tmp = realloc(crash.ranges, + sizeof(*crash.ranges) * (crash.rangeCount + 1)); + if (!tmp) + { + DEBUG_ERROR("out of memory"); + return 1; + } + crash.ranges = tmp; crash.ranges[crash.rangeCount].start = info->dlpi_addr; crash.ranges[crash.rangeCount].end = info->dlpi_addr + ttl; ++crash.rangeCount; diff --git a/host/src/app.c b/host/src/app.c index 0302fa23..df86b960 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -626,12 +626,13 @@ static bool appendData(KVMFRUserData * dst, const void * src, const size_t size) if (size > dst->size - dst->used) { size_t newSize = dst->size + max(1024, size); - dst->data = realloc(dst->data, newSize); - if (!dst->data) + void * tmp = realloc(dst->data, newSize); + if (!tmp) { DEBUG_ERROR("Out of memory"); return false; } + dst->data = tmp; memset(dst->data + dst->size, 0, newSize - dst->size); dst->size = newSize;