diff --git a/src/core/net/dns_client.cpp b/src/core/net/dns_client.cpp index 769314eff..1211db5f0 100644 --- a/src/core/net/dns_client.cpp +++ b/src/core/net/dns_client.cpp @@ -564,7 +564,7 @@ Error Client::StartQuery(QueryInfo & aInfo, SuccessOrExit(error = AllocateQuery(aInfo, aLabel, aName, query)); mQueries.Enqueue(*query); - SendQuery(*query); + SendQuery(*query, aInfo, /* aUpdateTimer */ true); exit: return error; @@ -597,15 +597,6 @@ void Client::FreeQuery(Query &aQuery) aQuery.Free(); } -void Client::SendQuery(Query &aQuery) -{ - QueryInfo info; - - info.ReadFrom(aQuery); - - SendQuery(aQuery, info, /* aUpdateTimer */ true); -} - void Client::SendQuery(Query &aQuery, QueryInfo &aInfo, bool aUpdateTimer) { // This method prepares and sends a query message represented by @@ -788,6 +779,11 @@ void Client::ProcessResponse(const Message &aMessage) response.mMessage = &aMessage; + // We intentionally parse the response in a separate method + // `ParseResponse()` to free all the stack allocated variables + // (e.g., `QueryInfo`) used during parsing of the message before + // finalizing the query and invoking the user's callback. + SuccessOrExit(ParseResponse(response, type, responseError)); FinalizeQuery(response, type, responseError); diff --git a/src/core/net/dns_client.hpp b/src/core/net/dns_client.hpp index 23eea18e5..3fd4f95b6 100644 --- a/src/core/net/dns_client.hpp +++ b/src/core/net/dns_client.hpp @@ -655,7 +655,6 @@ private: Error AllocateQuery(const QueryInfo &aInfo, const char *aLabel, const char *aName, Query *&aQuery); void FreeQuery(Query &aQuery); void UpdateQuery(Query &aQuery, const QueryInfo &aInfo) { aQuery.Write(0, aInfo); } - void SendQuery(Query &aQuery); void SendQuery(Query &aQuery, QueryInfo &aInfo, bool aUpdateTimer); void FinalizeQuery(Query &aQuery, Error aError); void FinalizeQuery(Response &Response, QueryType aType, Error aError);