Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: Adding/Removing network adapters in Windows can cause a null… #1633

Merged
merged 1 commit into from
Mar 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/ziflist.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,28 @@ s_reload (ziflist_t *self, bool ipv6)
DWORD rc = GetAdaptersAddresses (AF_INET, GAA_FLAG_INCLUDE_PREFIX, NULL, NULL, &addr_size);
assert (rc == ERROR_BUFFER_OVERFLOW);

PIP_ADAPTER_ADDRESSES pip_addresses = (PIP_ADAPTER_ADDRESSES) zmalloc (addr_size);
rc = GetAdaptersAddresses (AF_INET,
GAA_FLAG_INCLUDE_PREFIX, NULL, pip_addresses, &addr_size);
static const int maxTries = 3;
int iterations = 0;

PIP_ADAPTER_ADDRESSES pip_addresses = NULL;

do {
pip_addresses = (PIP_ADAPTER_ADDRESSES) zmalloc (addr_size);
rc = GetAdaptersAddresses (AF_INET,
GAA_FLAG_INCLUDE_PREFIX, NULL, pip_addresses, &addr_size);

if (rc == ERROR_BUFFER_OVERFLOW) {
free (pip_addresses);
pip_addresses = NULL;
}
else {
break;
}

++iterations;
}
while ((rc == ERROR_BUFFER_OVERFLOW) && (iterations < maxTries));

assert (rc == NO_ERROR);

PIP_ADAPTER_ADDRESSES cur_address = pip_addresses;
Expand Down