mirror of
https://github.com/nmap/nmap.git
synced 2026-08-30 05:37:05 +00:00
Avoid realloc leak
This commit is contained in:
parent
8d5b6f3388
commit
2708a5b399
1 changed files with 10 additions and 2 deletions
|
|
@ -92,15 +92,23 @@ _ifcombo_type(const char *device)
|
|||
static void
|
||||
_ifcombo_add(struct ifcombo *ifc, DWORD ipv4_idx, DWORD ipv6_idx)
|
||||
{
|
||||
void* pmem = NULL;
|
||||
if (ifc->cnt == ifc->max) {
|
||||
if (ifc->idx) {
|
||||
ifc->max *= 2;
|
||||
ifc->idx = realloc(ifc->idx,
|
||||
pmem = realloc(ifc->idx,
|
||||
sizeof(ifc->idx[0]) * ifc->max);
|
||||
} else {
|
||||
ifc->max = 8;
|
||||
ifc->idx = malloc(sizeof(ifc->idx[0]) * ifc->max);
|
||||
pmem = malloc(sizeof(ifc->idx[0]) * ifc->max);
|
||||
}
|
||||
if (!pmem) {
|
||||
/* malloc or realloc failed. Restore state.
|
||||
* TODO: notify caller. */
|
||||
ifc->max = ifc->cnt;
|
||||
return;
|
||||
}
|
||||
ifc->idx = pmem;
|
||||
}
|
||||
ifc->idx[ifc->cnt].ipv4 = ipv4_idx;
|
||||
ifc->idx[ifc->cnt].ipv6 = ipv6_idx;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue