[reSIProcate] Memory leaks in Helper.cxx
- From: Volodymyr Tarasenko <tvntsr@xxxxxxxxx>
- Date: Tue, 19 Oct 2010 11:54:07 -0700 (PDT)
Hi,
As I see there is a memory leak in Helper in some circumstances.
For example, let see a Helper::makeRequest(const NameAddr& target, const
NameAddr& from, const NameAddr& contact, MethodTypes method).
At the first line a new sip message is allocated but in case of exception this
object will never be deleted. Exception is possible if some badly formed values
are in NameAddr...
The fix is in attach.
Regards,
Volodymyr!
--- resip/stack/Helper.cxx
+++ resip/stack/Helper.cxx
@@ -118,7 +118,7 @@
SipMessage*
Helper::makeRequest(const NameAddr& target, const NameAddr& from, const NameAddr& contact, MethodTypes method)
{
- SipMessage* request = new SipMessage;
+ std::auto_ptr<SipMessage> request(new SipMessage);
RequestLine rLine(method);
rLine.uri() = target.uri();
request->header(h_To) = target;
@@ -135,7 +135,7 @@
Via via;
request->header(h_Vias).push_back(via);
- return request;
+ return request.release();
}
SipMessage*
@@ -155,7 +155,7 @@
SipMessage*
Helper::makeRegister(const NameAddr& to, const NameAddr& from, const NameAddr& contact)
{
- SipMessage* request = new SipMessage;
+ std::auto_ptr<SipMessage> request(new SipMessage);
RequestLine rLine(REGISTER);
rLine.uri().scheme() = to.uri().scheme();
@@ -180,7 +180,7 @@
Via via;
request->header(h_Vias).push_back(via);
- return request;
+ return request.release();
}
SipMessage*
@@ -194,7 +194,7 @@
SipMessage*
Helper::makeRegister(const NameAddr& to, const Data& transport, const NameAddr& contact)
{
- SipMessage* request = new SipMessage;
+ std::auto_ptr<SipMessage> request(new SipMessage);
RequestLine rLine(REGISTER);
rLine.uri().scheme() = to.uri().scheme();
@@ -219,7 +219,7 @@
Via via;
request->header(h_Vias).push_back(via);
- return request;
+ return request.release();
}
@@ -233,7 +233,7 @@
SipMessage*
Helper::makePublish(const NameAddr& target, const NameAddr& from, const NameAddr& contact)
{
- SipMessage* request = new SipMessage;
+ std::auto_ptr<SipMessage> request(new SipMessage);
RequestLine rLine(PUBLISH);
rLine.uri() = target.uri();
@@ -250,7 +250,7 @@
Via via;
request->header(h_Vias).push_back(via);
- return request;
+ return request.release();
}
SipMessage*
@@ -263,7 +263,7 @@
SipMessage*
Helper::makeMessage(const NameAddr& target, const NameAddr& from, const NameAddr& contact)
{
- SipMessage* request = new SipMessage;
+ std::auto_ptr<SipMessage> request(new SipMessage);
RequestLine rLine(MESSAGE);
rLine.uri() = target.uri();
@@ -280,7 +280,7 @@
Via via;
request->header(h_Vias).push_back(via);
- return request;
+ return request.release();
}
@@ -294,7 +294,7 @@
SipMessage*
Helper::makeSubscribe(const NameAddr& target, const NameAddr& from, const NameAddr& contact)
{
- SipMessage* request = new SipMessage;
+ std::auto_ptr<SipMessage> request(new SipMessage);
RequestLine rLine(SUBSCRIBE);
rLine.uri() = target.uri();
@@ -311,7 +311,7 @@
Via via;
request->header(h_Vias).push_front(via);
- return request;
+ return request.release();
}
int
@@ -550,7 +550,7 @@
{
assert(request.isRequest());
assert(request.header(h_RequestLine).getMethod() == INVITE);
- SipMessage* cancel = new SipMessage;
+ std::auto_ptr<SipMessage> cancel(new SipMessage);
RequestLine rLine(CANCEL, request.header(h_RequestLine).getSipVersion());
rLine.uri() = request.header(h_RequestLine).uri();
@@ -577,7 +577,7 @@
cancel->header(h_CSeq).method() = CANCEL;
cancel->header(h_Vias).push_back(request.header(h_Vias).front());
- return cancel;
+ return cancel.release();
}
@@ -587,7 +587,7 @@
assert (request.header(h_Vias).size() >= 1);
assert (request.header(h_RequestLine).getMethod() == INVITE);
- SipMessage* ack = new SipMessage;
+ std::auto_ptr<SipMessage> ack(new SipMessage);
RequestLine rLine(ACK, request.header(h_RequestLine).getSipVersion());
rLine.uri() = request.header(h_RequestLine).uri();
@@ -604,7 +604,7 @@
ack->header(h_Routes) = request.header(h_Routes);
}
- return ack;
+ return ack.release();
}