Repository navigation
Commit e625eef
committed
[BUG] Remove a curl easy handle before releasing what it points at
Teardown touched the easy handle in the wrong order and on the wrong thread.
Cleanup cleared CURLOPT_PRIVATE and called curl_easy_reset on it, from
whichever thread ran the cancel, while the transfer could still be active.
doRemoveSessions then freed the header list before curl_multi_remove_handle
and cleaned the handle up whatever that call returned.
libcurl is explicit on all three: changing options while a transfer is in
progress may have undefined behaviour, the header list has to outlive the
handle that points at it, and a handle has to leave the multi handle before it
can be cleaned up.
Cleanup now hands the resource over untouched. doRemoveSessions removes it,
checks the CURLMcode, and only then frees the list and the handle. A failed
removal leaves both alone: leaking one easy handle is better than freeing one
the multi stack may still own. A handle that was never added reports CURLM_OK,
so no separate bookkeeping is needed to tell the two apart.
Clearing CURLOPT_PRIVATE was load bearing rather than tidy up. The IO loop
reads it back to decide whether a CURLMSG_DONE belongs to a session that has
already gone, so PerformCurlMessage checks is_cleaned_ instead. That keeps the
behaviour without writing to a handle from a thread that does not own it.
Fixes #4391.
Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>1 parent a31138b commit e625eef
3 files changed
Lines changed: 44 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | | - | |
37 | | - | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
811 | 811 | | |
812 | 812 | | |
813 | 813 | | |
814 | | - | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
815 | 837 | | |
816 | | - | |
| 838 | + | |
| 839 | + | |
817 | 840 | | |
818 | 841 | | |
819 | | - | |
820 | | - | |
| 842 | + | |
| 843 | + | |
821 | 844 | | |
822 | 845 | | |
823 | 846 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
545 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
546 | 549 | | |
547 | 550 | | |
548 | 551 | | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | 552 | | |
555 | 553 | | |
556 | 554 | | |
| |||
1525 | 1523 | | |
1526 | 1524 | | |
1527 | 1525 | | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
1528 | 1534 | | |
1529 | 1535 | | |
1530 | 1536 | | |
| |||
0 commit comments