Skip to content

clear mdns.queryservice()'s previous result when called #4894

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

Merged
merged 4 commits into from
Jul 6, 2018
Merged
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion libraries/ESP8266mDNS/ESP8266mDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,15 @@ int MDNSResponder::queryService(char *service, char *proto) {
#ifdef DEBUG_ESP_MDNS_TX
DEBUG_ESP_PORT.printf("queryService %s %s\n", service, proto);
#endif

MDNSAnswer *answer;
int numAnswers = _getNumAnswers();
for (int n = numAnswers - 1; n >= 0; n--) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answers is implemented as a linked list. This implementation will search the linked list from front to back for each iteration in order to find the last one for removal, which is an exponential algorithm.
Could you please reimplement the clearing of the answers by just iterating through the list and freeing each?

answer = _getAnswerFromIdx(n);
os_free(answer->hostname);
os_free(answer);
answer = 0;
}
_answers = 0;
if (_query != 0) {
os_free(_query);
_query = 0;
Expand Down