cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: invalid free after an http redirect to ftp

From: Michal Marek <mmarek_at_suse.cz>
Date: Sat, 13 Oct 2007 11:24:06 +0200

Daniel Stenberg wrote:
> Please try the attached patch attempt...

Thanks, that helped with the http-redirect-to-ftp testcase,
unfortunately it breaks again here:

$ ./libtool --mode=execute valgrind ./src/curl -v \
ftp://ftp.kernel.org/welcome.msg http://example.org/
...
* About to connect() to ftp.kernel.org port 21 (#0)
...
< 226 File send OK.
* Connection #0 to host ftp.kernel.org left intact
...
* About to connect() to example.org port 80 (#1)
...
* Closing connection #1 (this goes ok)
> QUIT
< 221 Goodbye.
==12420== Invalid free() / delete / delete[]
==12420== at 0x4C2191B: free (in
/usr/lib64/valgrind/amd64-linux/vgpreload_memcheck.so)
==12420== by 0x4E406D1: freedirs (ftp.c:281)
==12420== by 0x4E465C7: Curl_ftp_disconnect (ftp.c:3819)
==12420== by 0x4E4D10B: Curl_disconnect (url.c:2083)
==12420== by 0x4E4D9F4: ConnectionKillOne (url.c:2462)
==12420== by 0x4E473B3: close_connections (url.c:296)
==12420== by 0x4E47676: Curl_close (url.c:453)
==12420== by 0x4E5F59F: curl_easy_cleanup (easy.c:513)
==12420== by 0x40AF9B: operate (main.c:4665)
==12420== by 0x40B14F: main (main.c:4724)
==12420== Address 0x4E6EB49 is not stack'd, malloc'd or (recently) free'd
* Closing connection #0 (this caused the error - the msg is printed
after the handler is called)

I think I can see the problem now and even a possible solution: The ftp
code stores data in struct SessionHandle as well as in struct
connectdata, and in the case above backtrace it tries to free data in
SessionHandle that's no longer there. My idea is to split the cleanup
into two callbacks: free the per-connection data in
Curl_handler::disconnect() and add a new callback to struct
SessionHandle (like you did) that deals with per-session data. I'll
provide a patch later today or on Monday.

Hmm, another (much simpler) option would be to move FTP::file to struct
connectdata.

I guess Daniel is busy preparing for his trip atm, can anyone else
comment on this?

Michal
Received on 2007-10-13