Skip to content

Commit ad70bbd

Browse files
SjordLamentXU123
authored andcommitted
Fix leak when cURL PREREQFUNCTION returns a type other than int (#22726)
The return value of the function registered with CURLOPT_PREREQFUNCTION was not cleaned up when it returned an invalid non-int type. Destroy the callback return value before throwing a TypeError. The test now returns a dynamically allocated array containing random_bytes(), so leak detection exercises the zval cleanup path reliably. Closes #22726
1 parent 68d605f commit ad70bbd

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

ext/curl/interface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ static int curl_prereqfunction(void *clientp, char *conn_primary_ip, char *conn_
770770
zend_value_error("The CURLOPT_PREREQFUNCTION callback must return either CURL_PREREQFUNC_OK or CURL_PREREQFUNC_ABORT");
771771
}
772772
} else {
773+
zval_ptr_dtor(&retval);
773774
zend_type_error("The CURLOPT_PREREQFUNCTION callback must return either CURL_PREREQFUNC_OK or CURL_PREREQFUNC_ABORT");
774775
}
775776
}

ext/curl/tests/curl_setopt_CURLOPT_PREREQFUNCTION.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ try {
7777

7878
echo "\nTesting with invalid type\n";
7979
curl_setopt($ch, CURLOPT_PREREQFUNCTION, function() use ($port) {
80-
return 'this should be an integer';
80+
return ['this should be an integer' => random_bytes(64)];
8181
});
8282
try {
8383
curl_exec($ch);

0 commit comments

Comments
 (0)