[reSIProcate] Memory leak patch for DnsInterface.cxx
Hi,
I've attached a patch that fixes a small memory leak in
DnsInterface::errorMessage() that occurs because the c string returned on the
heap by ExternalDns::errorMessage() is not deleted. The patch also modifies
AresDns::errorMessage() in AresDns.cxx to append a null character to the
error string, since the Data() constructor uses strlen() which requires the
presence of a null char.
Regards,
~Scott
Index: resiprocate/DnsInterface.cxx
===================================================================
--- resiprocate/DnsInterface.cxx (revision 3812)
+++ resiprocate/DnsInterface.cxx (working copy)
@@ -76,7 +76,7 @@
Data
DnsInterface::errorMessage(int status)
{
- return Data(mDnsProvider->errorMessage(status));
+ return Data(Data::Take, mDnsProvider->errorMessage(status));
}
void
Index: resiprocate/AresDns.cxx
===================================================================
--- resiprocate/AresDns.cxx (revision 3812)
+++ resiprocate/AresDns.cxx (working copy)
@@ -148,9 +148,10 @@
const char* aresMsg = ares_strerror(errorCode);
int len = strlen(aresMsg);
- char* errorString = new char[len];
+ char* errorString = new char[len+1];
strncpy(errorString, aresMsg, len);
+ errorString[len] = '\0';
return errorString;
}