diff options
author | peculiar-pooja <pooja.desai10@gmail.com> | 2022-04-14 00:23:47 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-14 00:23:47 +0530 |
commit | a0976e2287e52ecf86ee098d2f593762390493e3 (patch) | |
tree | 608ad242ff4cc2c842def59d3fd08d366550059a /erts/emulator/drivers | |
parent | 511dedd19dfee5d690621f47261504d02809e4e6 (diff) | |
download | erlang-a0976e2287e52ecf86ee098d2f593762390493e3.tar.gz |
changes to fix erlang hung issue on IPv6 setup
Fixing problem in inet_drv.c where code is crashing due to infinite loop while searching interfaces
Also updated code to avoid use of uninitialised pointer and updated macro to set variable to NULL after free.
Diffstat (limited to 'erts/emulator/drivers')
-rw-r--r-- | erts/emulator/drivers/common/inet_drv.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c index cf3c5fa3f6..b6bd30481f 100644 --- a/erts/emulator/drivers/common/inet_drv.c +++ b/erts/emulator/drivers/common/inet_drv.c @@ -1558,12 +1558,14 @@ static void *realloc_wrapper(void *current, ErlDrvSizeT size){ return ret; } #define REALLOC(X,Y) realloc_wrapper(X,Y) -#define FREE(P) driver_free((P)) +#define FREE(P) { driver_free((P)); \ + (P) = NULL;} #else /* FATAL_MALLOC */ #define ALLOC(X) driver_alloc((X)) #define REALLOC(X,Y) driver_realloc((X), (Y)) -#define FREE(P) driver_free((P)) +#define FREE(P) { driver_free((P)); \ + (P) = NULL;} #endif /* FATAL_MALLOC */ @@ -5840,9 +5842,10 @@ static ErlDrvSSizeT inet_ctl_getifaddrs(inet_descriptor* desc_p, { int i; DWORD ret, n; - IP_INTERFACE_INFO *info_p; - MIB_IPADDRTABLE *ip_addrs_p; - IP_ADAPTER_ADDRESSES *ip_adaddrs_p, *ia_p; + IP_INTERFACE_INFO *info_p = NULL; + MIB_IPADDRTABLE *ip_addrs_p = NULL; + IP_ADAPTER_ADDRESSES *ip_adaddrs_p = NULL; + IP_ADAPTER_ADDRESSES *ia_p = NULL; char *buf_p; char *buf_alloc_p; @@ -5901,10 +5904,10 @@ static ErlDrvSSizeT inet_ctl_getifaddrs(inet_descriptor* desc_p, if (ret == NO_ERROR) break; if (ret == ERROR_BUFFER_OVERFLOW) continue; i = 0; + break; } if (! i) { FREE(ip_adaddrs_p); - ip_adaddrs_p = NULL; } } else ip_adaddrs_p = NULL; } @@ -5921,11 +5924,9 @@ static ErlDrvSSizeT inet_ctl_getifaddrs(inet_descriptor* desc_p, if (ret == NO_ERROR) break; if (ret == ERROR_INSUFFICIENT_BUFFER) continue; i = 0; + break; } - if (! i) { - FREE(info_p); - info_p = NULL; - } + if (! i) FREE(info_p); } if (! ip_adaddrs_p) { @@ -5940,6 +5941,7 @@ static ErlDrvSSizeT inet_ctl_getifaddrs(inet_descriptor* desc_p, if (ret == NO_ERROR) break; if (ret == ERROR_INSUFFICIENT_BUFFER) continue; i = 0; + break; } if (! i) { if (info_p) FREE(info_p); @@ -5982,13 +5984,14 @@ index: } else { /* Then try IP_ADAPTER_INDEX_MAP.Name (only IPv4 adapters) */ int j; - for (j = 0; j < info_p->NumAdapters; j++) { - if (info_p->Adapter[j].Index == (ULONG) ifrow.dwIndex) { - if (info_p->Adapter[j].Name[0] != 0) { - wname_p = info_p->Adapter[j].Name; + if (info_p) { + for (j = 0; j < info_p->NumAdapters; j++) { + if (info_p->Adapter[j].Index == (ULONG) ifrow.dwIndex) { + if (info_p->Adapter[j].Name[0] != 0) { + wname_p = info_p->Adapter[j].Name; + } + break; } - break; - } } } if (wname_p) { @@ -13516,7 +13519,7 @@ subs_list *subs; this = subs->next; while(this) { next = this->next; - FREE((void *) this); + FREE(this); this = next; } @@ -13547,7 +13550,7 @@ static void send_to_subscribers if(free_subs && !first) { next = this->next; - FREE((void *) this); + FREE(this); this = next; } else |