1--TEST--
2curl_multi_add_handle does not hold onto the handle on failure
3--EXTENSIONS--
4curl
5--FILE--
6<?php
7
8class MyClass {
9    public function __destruct() {
10        echo __METHOD__, PHP_EOL;
11    }
12}
13
14$urls = [
15    "file://".__DIR__."/curl_testdata1.txt",
16    "file://".__DIR__."/curl_testdata2.txt",
17];
18
19$mh = curl_multi_init();
20
21$toRemove = [];
22foreach ($urls as $url) {
23    $ch = curl_init($url);
24    curl_setopt($ch, CURLOPT_PRIVATE, new MyClass());
25
26    if (curl_multi_add_handle($mh, $ch) == CURLM_OK) {
27        $toRemove[] = $ch;
28    }
29    if (curl_multi_add_handle($mh, $ch) == CURLM_OK) {
30        $toRemove[] = $ch;
31    }
32
33    unset($ch);
34}
35
36echo "Removing", PHP_EOL;
37foreach ($toRemove as $i => $ch) {
38    curl_multi_remove_handle($mh, $ch);
39    unset($ch);
40    unset($toRemove[$i]);
41}
42echo "Removed", PHP_EOL;
43
44?>
45--EXPECTF--
46Removing
47MyClass::__destruct
48MyClass::__destruct
49Removed
50