Calls to nua_respond, or any other method that sends or receives a response, 
should always be considered an async operation.  A reasonable approach would be 
to use the memory home associated with that handle (nua_handle_home) to 
allocate the data - the data would be automatically released when the handle is 
destroyed.  If that particular message is generated multiple times for each 
handle, use the application pointer (nua_handle_magic) to avoid a memory leak.

-Jarod

-----Original Message-----
From: Martin Drasar [mailto:dra...@optimsys.cz] 
Sent: Wednesday, March 03, 2010 4:48 AM
To: sofia-sip-devel@lists.sourceforge.net
Subject: [Sofia-sip-devel] nua_respond and deallocated memory

Hello everyone,
I have a question regarding the nua_respond() function.

I have encountered a problem with this construct:


void doSomething()
{
  std::string message;

  switch()
  {
    case a: message = "something"; break;
    case b: message = "soemthing else"; break;
  }

  nua_respond(nh, status, message.c_str());

  return;
}

It sometimes happens that the string gets destroyed before the actual message 
gets sent and as a result the SIP message contains random data.

In this case the easy remedy is to use const char* instead of std::string, but 
if I wanted to use dynamic data, I am out of luck. I presume that there is some 
internal queue that holds these request before sending them and this queue does 
not copy the data provided and use supplied pointers instead.

My question is what should I do if I want to pass dynamically constructed data 
tu nua_respond (and maybe some other) function? Should I allocate the data and 
free them when the conection is closed? [Not a big fan of this approach.] Or is 
there some event that is going to tell me - your structure is ready to be 
released? Or have I missed someting obvious?

Thank you for your answer

Regards
Martin

--
  Martin Drasar, Developer / Analyst
  OptimSys, s.r.o.
  dra...@optimsys.cz
  Tel: +420 541 143 065
  Fax: +420 541 143 066
  http://www.optimsys.cz


------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Sofia-sip-devel mailing list
Sofia-sip-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel

Reply via email to