Skip to content

[FIX] MDNS queryService emtpy buffer before query service #3076

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
17 changes: 11 additions & 6 deletions libraries/ESP8266mDNS/ESP8266mDNS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ struct MDNSQuery {
char _proto[4];
};


MDNSResponder::MDNSResponder() : _conn(0) {
_services = 0;
_instanceName = "";
void MDNSResponder::_initVar() {
_answers = 0;
_query = 0;
_newQuery = false;
_waitingForAnswers = false;
}

MDNSResponder::MDNSResponder() : _conn(0) {
_initVar();
_services = 0;
_instanceName = "";
}
MDNSResponder::~MDNSResponder() {
if (_query != 0) {
os_free(_query);
Expand Down Expand Up @@ -283,7 +286,9 @@ int MDNSResponder::queryService(char *service, char *proto) {
#ifdef MDNS_DEBUG_TX
Serial.printf("queryService %s %s\n", service, proto);
#endif


_initVar();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will cause a mem leak on _query


if (_query != 0) {
os_free(_query);
_query = 0;
Expand All @@ -292,7 +297,7 @@ int MDNSResponder::queryService(char *service, char *proto) {
os_strcpy(_query->_service, service);
os_strcpy(_query->_proto, proto);
_newQuery = true;

char underscore[] = "_";

// build service name with _
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP8266mDNS/ESP8266mDNS.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class MDNSResponder {
WiFiEventHandler _gotIPHandler;


void _initVar();
uint16_t _getServicePort(char *service, char *proto);
MDNSTxt * _getServiceTxt(char *name, char *proto);
uint16_t _getServiceTxtLen(char *name, char *proto);
Expand Down