Hi Ben/libuv team,

While analysing the memory allocation with valgrind memory analyser tool, 
I've observed the following error while calling free() in uv_close's 
callback :

==32732== 
==32732== Invalid free() / delete / delete[]
==32732==    at 0x4004FDA: free (vg_replace_malloc.c:233)
==32732==    by 0x80521A3: uv__finish_close (core.c:204)
==32732==    by 0x80521DA: uv__run_closing_handles (core.c:218)
==32732==    by 0x8052457: uv_run (core.c:316)
==32732==    by 0x8050328: ppp (ppp.c:96)
==32732==    by 0x804AD79: main (main.c:108)
==32732==  Address 0x806B880 is not stack'd, malloc'd or (recently) free'd
==32732== 

The code for the same is :

void on_file_write(uv_write_t *req, int status) {
        uv_close( (uv_handle_t*) req->handle, (uv_close_cb) free );
        free( req->data );
}

uv_write(writer, (uv_stream_t*) &req_file, &buf, 1, on_file_write);

Please resolve.

Regards,
Sarav

On Tuesday, November 19, 2013 4:42:37 PM UTC+5:30, Ben Noordhuis wrote:
>
> On Mon, Nov 18, 2013 at 10:23 PM, Aaron Boxer <[email protected]<javascript:>> 
> wrote: 
> > In the code below, do I need to free the client, or will it be done by 
> > uv_close? 
> > 
> > Thanks! 
> > Aaron 
> > 
> > 
> > /////////////////////////////////////////////////////// 
> > uv_tcp_t* client  =  ( uv_tcp_t * )  malloc ( sizeof ( uv_tcp_t )); 
> > 
> > ... 
> > 
> > 
> >  uv_close (( uv_handle_t * )  client ,  NULL ); 
>
> You should free it yourself but only from the close callback.  You can 
> use `uv_close(handle, (uv_close_cb) free)` for that. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to