Skip to content

Commit d637f0d

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Retain reference to share handle from curl handle
2 parents 329d38c + b4a2a96 commit d637f0d

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

ext/curl/curl_private.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ typedef struct {
104104
zend_bool in_callback;
105105
uint32_t* clone;
106106
zval postfields;
107+
/* CurlShareHandle object set using CURLOPT_SHARE. */
108+
struct _php_curlsh *share;
107109
zend_object std;
108110
} php_curl;
109111

@@ -124,7 +126,7 @@ typedef struct {
124126
zend_object std;
125127
} php_curlm;
126128

127-
typedef struct {
129+
typedef struct _php_curlsh {
128130
CURLSH *share;
129131
struct {
130132
int no;

ext/curl/interface.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,6 +2832,12 @@ static int _php_curl_setopt(php_curl *ch, zend_long option, zval *zvalue, bool i
28322832
if (Z_TYPE_P(zvalue) == IS_OBJECT && Z_OBJCE_P(zvalue) == curl_share_ce) {
28332833
php_curlsh *sh = Z_CURL_SHARE_P(zvalue);
28342834
curl_easy_setopt(ch->cp, CURLOPT_SHARE, sh->share);
2835+
2836+
if (ch->share) {
2837+
OBJ_RELEASE(&ch->share->std);
2838+
}
2839+
GC_ADDREF(&sh->std);
2840+
ch->share = sh;
28352841
}
28362842
}
28372843
break;
@@ -3373,6 +3379,10 @@ static void curl_free_obj(zend_object *object)
33733379
efree(ch->handlers);
33743380
zval_ptr_dtor(&ch->postfields);
33753381

3382+
if (ch->share) {
3383+
OBJ_RELEASE(&ch->share->std);
3384+
}
3385+
33763386
zend_object_std_dtor(&ch->std);
33773387
}
33783388
/* }}} */

ext/curl/tests/curl_share_basic.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Basic curl_share test
3+
--FILE--
4+
<?php
5+
6+
$sh = curl_share_init();
7+
8+
$ch1 = curl_init();
9+
curl_setopt($ch1, CURLOPT_URL, 'file://' . __DIR__ . '/curl_testdata1.txt');
10+
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
11+
curl_setopt($ch1, CURLOPT_SHARE, $sh);
12+
13+
$ch2 = curl_init();
14+
curl_setopt($ch2, CURLOPT_URL, 'file://' . __DIR__ . '/curl_testdata2.txt');
15+
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
16+
curl_setopt($ch2, CURLOPT_SHARE, $sh);
17+
18+
// Make sure nothing bad handles if the share handle is unset early.
19+
unset($sh);
20+
21+
var_dump(curl_exec($ch1));
22+
var_dump(curl_exec($ch2));
23+
24+
?>
25+
--EXPECT--
26+
string(6) "CURL1
27+
"
28+
string(6) "CURL2
29+
"

0 commit comments

Comments
 (0)