mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-09 20:24:14 +00:00
[all] general: fix possible memory leaks with realloc usage
This commit is contained in:
@@ -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;
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user