logo       

Re: memory leak in udp roundtrip example?: msg#00028

lib.boost.asio.user

Subject: Re: memory leak in udp roundtrip example?

Hi Charlls,

Charlls Quarra wrote:
> I was trying to find the source of a leak in my asio
> application (nothing outrageously big, but it could
> exhaust 1Gb in a day or so), and i keep reducing the
> code until i reached a minimal skeleton that
> reproduces the leak. I'm not sure if it has been
> reported already since there are no bugs filed in the
> tracker, so i assume it's safe to post it here.

Ok, i'll take a look, however I have spotted a bug in your program :)

The data passed to async_send_to must be valid for the lifetime of the
operation (i.e. until the handler is called), but the string argument
"str" in this function:

> void start_send_to(string& str , udp::endpoint& endp)
> {
> //strncpy( data_ , str.c_str() , max_length-1 );
> socket_.async_send_to( asio::buffer( str.c_str() ,
> max_length ) , endp ,
>
> boost::bind(&server::handle_send_to , this,
>
> asio::placeholders::error ,
>
> asio::placeholders::bytes_transferred));
> }

Is on the stack at this point in io_main():

> if ( arg->offset_port != -1 )
> {
> // this side will start the echo
> udp::resolver::query query(udp::v4(), "0.0.0.0",
> "0");
> udp::endpoint endp = *resolver.resolve(query);
> endp.port( arg->port + arg->offset_port );
> string foo;
> foo = "foob\n";
> //foo = "fooBistic";
> s.start_send_to( *& foo , *& endp );
>
> }

and it goes out of scope before the io_service::run(), and so does not
have the correct lifetime.

> io_service.run();

I'm not sure if this is related to the leak (it probably isn't) but it
should be fixed and the leak test rerun.

Cheers,
Chris

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise