Repository navigation
Commit f4a41eb
committed
[BUG] Clear a detached easy handle before freeing it
curl_easy_cleanup documents that it can reach the application: "Occasionally
you may get your progress callback or header callback called from within
curl_easy_cleanup (if previously set for the handle using curl_easy_setopt)",
for protocols that need a command and response before disconnecting.
By then the event handler is gone. The only shared_ptr to it is captured in the
completion callback that SendRequest builds, Cleanup swaps that out and runs
it, and it is released when Cleanup returns. The write, header and read
callbacks all dispatch through the raw pointer the operation keeps, so the one
libcurl says it may call is the one with nothing behind it.
Clearing the handle first takes the callbacks and their data off it, so freeing
it cannot reach anything the client has let go of, and the header list is freed
after that because libcurl does not copy it and the clear is what stops it
being read.
This runs on the background thread with the handle detached, which is what the
version removed from Cleanup earlier on this branch could not say: that one ran
on whichever thread cancelled, against a handle the multi handle still held.
Measured on 8.14.1 over HTTP, neither curl_multi_remove_handle nor
curl_easy_cleanup reaches a callback once the transfer has finished, and
removing a handle from a live transfer reaches the progress callback once. So
nothing here is what stops a failure today over HTTP. What it stops is the
call libcurl reserves the right to make.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>1 parent 36bd6e6 commit f4a41eb
1 file changed
Lines changed: 13 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
58 | | - | |
59 | | - | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
67 | 76 | | |
68 | 77 | | |
69 | 78 | | |
| |||
0 commit comments