-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
NameResolutionPal.Unix enabled async name resolution #34633
Changes from 1 commit
fc09ca1
8c955bc
cf13c70
4614267
1b2daab
b9629e9
6f64c86
e7df0cc
d7cb2be
74b3031
775ff72
ec8522f
298cf03
458579b
8f69164
8cec5fb
f3ebd6a
cf45cc9
43f889f
bd16c74
ed5c39f
b8efde5
04dbd8e
37e4dd3
7176378
b64867b
900834e
198717e
f85c316
438c75a
89c266f
33da8da
fa9c6f9
8266dd3
75e52c7
89a7c5a
dd1e245
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -428,7 +428,7 @@ struct GetAddrInfoAsyncState | |
struct gaicb* gai_requests; | ||
struct sigevent sigevent; | ||
|
||
const uint8_t* address; | ||
uint8_t* address; | ||
HostEntry* entry; | ||
GetHostEntryForNameCallback callback; | ||
}; | ||
|
@@ -456,6 +456,7 @@ static void GetHostEntryForNameAsyncComplete(sigval_t context) | |
callback(state->entry, ret); | ||
} | ||
|
||
free(state->address); | ||
free(state); | ||
} | ||
#endif | ||
|
@@ -501,9 +502,11 @@ int32_t SystemNative_GetHostEntryForNameAsync(const uint8_t* address, HostEntry* | |
return GetAddrInfoErrorFlags_EAI_MEMORY; | ||
} | ||
|
||
*state = (struct GetAddrInfoAsyncState){ | ||
char* localAddress = strdup((const char*)address); | ||
|
||
*state = (struct GetAddrInfoAsyncState) { | ||
.gai_request = { | ||
.ar_name = (const char*)address, | ||
.ar_name = localAddress, | ||
.ar_service = NULL, | ||
.ar_request = &s_hostEntryForNameHints, | ||
.ar_result = NULL | ||
|
@@ -516,7 +519,7 @@ int32_t SystemNative_GetHostEntryForNameAsync(const uint8_t* address, HostEntry* | |
}, | ||
.sigev_notify_function = GetHostEntryForNameAsyncComplete | ||
}, | ||
.address = address, | ||
.address = (uint8_t*)localAddress, | ||
.entry = entry, | ||
.callback = callback | ||
}; | ||
|
@@ -527,6 +530,7 @@ int32_t SystemNative_GetHostEntryForNameAsync(const uint8_t* address, HostEntry* | |
|
||
if (result != 0) | ||
{ | ||
free(localAddress); | ||
free(state); | ||
return ConvertGetAddrInfoAndGetNameInfoErrorsToPal(result); | ||
} | ||
|
@@ -546,8 +550,15 @@ void SystemNative_FreeHostEntry(HostEntry* entry) | |
{ | ||
if (entry != NULL) | ||
{ | ||
free(entry->CanonicalName); | ||
free(entry->IPAddressList); | ||
if (entry->CanonicalName != NULL) | ||
{ | ||
free(entry->CanonicalName); | ||
} | ||
|
||
if (entry->IPAddressList != NULL) | ||
{ | ||
free(entry->IPAddressList); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: You don't need to null-check before calling free(). free() can take any value returned by malloc(), including NULL. (Change is harmless, but something to keep in mind.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the valuable input! Maybe it was an artefact of the bug hunt, but Valgrind complained this. That's why I changed this. Will revert to the cleaner version. |
||
|
||
entry->CanonicalName = NULL; | ||
entry->IPAddressList = NULL; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
malloc() result is NULL-checked but strdup() isn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do both allocations here in a single one by using a flexible member in struct GetAddrInfoAsyncState:
Also, I'd bail out if addrlen > 253 (hostnames can't be larger than that per the RFC; otherwise, you'd have to check for overflow before passing the len to malloc).