@@ -1204,6 +1204,17 @@ PHP_FUNCTION(curl_init)
1204
1204
}
1205
1205
/* }}} */
1206
1206
1207
+ static void _php_copy_callback (php_curl * ch , php_curl_callback * * new_callback , php_curl_callback * source_callback , CURLoption option )
1208
+ {
1209
+ if (source_callback ) {
1210
+ * new_callback = ecalloc (1 , sizeof (php_curl_callback ));
1211
+ if (!Z_ISUNDEF (source_callback -> func_name )) {
1212
+ ZVAL_COPY (& (* new_callback )-> func_name , & source_callback -> func_name );
1213
+ }
1214
+ curl_easy_setopt (ch -> cp , option , (void * ) ch );
1215
+ }
1216
+ }
1217
+
1207
1218
void _php_setup_easy_copy_handlers (php_curl * ch , php_curl * source )
1208
1219
{
1209
1220
if (!Z_ISUNDEF (source -> handlers .write -> stream )) {
@@ -1243,40 +1254,13 @@ void _php_setup_easy_copy_handlers(php_curl *ch, php_curl *source)
1243
1254
curl_easy_setopt (ch -> cp , CURLOPT_WRITEHEADER , (void * ) ch );
1244
1255
curl_easy_setopt (ch -> cp , CURLOPT_DEBUGDATA , (void * ) ch );
1245
1256
1246
- if (source -> handlers .progress ) {
1247
- ch -> handlers .progress = ecalloc (1 , sizeof (php_curl_callback ));
1248
- if (!Z_ISUNDEF (source -> handlers .progress -> func_name )) {
1249
- ZVAL_COPY (& ch -> handlers .progress -> func_name , & source -> handlers .progress -> func_name );
1250
- }
1251
- curl_easy_setopt (ch -> cp , CURLOPT_PROGRESSDATA , (void * ) ch );
1252
- }
1253
-
1257
+ _php_copy_callback (ch , & ch -> handlers .progress , source -> handlers .progress , CURLOPT_PROGRESSDATA );
1254
1258
#if LIBCURL_VERSION_NUM >= 0x072000
1255
- if (source -> handlers .xferinfo ) {
1256
- ch -> handlers .xferinfo = ecalloc (1 , sizeof (php_curl_callback ));
1257
- if (!Z_ISUNDEF (source -> handlers .xferinfo -> func_name )) {
1258
- ZVAL_COPY (& ch -> handlers .xferinfo -> func_name , & source -> handlers .xferinfo -> func_name );
1259
- }
1260
- curl_easy_setopt (ch -> cp , CURLOPT_XFERINFODATA , (void * ) ch );
1261
- }
1259
+ _php_copy_callback (ch , & ch -> handlers .xferinfo , source -> handlers .xferinfo , CURLOPT_XFERINFODATA );
1262
1260
#endif
1263
-
1264
- if (source -> handlers .fnmatch ) {
1265
- ch -> handlers .fnmatch = ecalloc (1 , sizeof (php_curl_callback ));
1266
- if (!Z_ISUNDEF (source -> handlers .fnmatch -> func_name )) {
1267
- ZVAL_COPY (& ch -> handlers .fnmatch -> func_name , & source -> handlers .fnmatch -> func_name );
1268
- }
1269
- curl_easy_setopt (ch -> cp , CURLOPT_FNMATCH_DATA , (void * ) ch );
1270
- }
1271
-
1261
+ _php_copy_callback (ch , & ch -> handlers .fnmatch , source -> handlers .fnmatch , CURLOPT_FNMATCH_DATA );
1272
1262
#if LIBCURL_VERSION_NUM >= 0x075400
1273
- if (source -> handlers .sshhostkey ) {
1274
- ch -> handlers .sshhostkey = ecalloc (1 , sizeof (php_curl_callback ));
1275
- if (!Z_ISUNDEF (source -> handlers .sshhostkey -> func_name )) {
1276
- ZVAL_COPY (& ch -> handlers .sshhostkey -> func_name , & source -> handlers .sshhostkey -> func_name );
1277
- }
1278
- curl_easy_setopt (ch -> cp , CURLOPT_SSH_HOSTKEYDATA , (void * ) ch );
1279
- }
1263
+ _php_copy_callback (ch , & ch -> handlers .sshhostkey , source -> handlers .sshhostkey , CURLOPT_SSH_HOSTKEYDATA );
1280
1264
#endif
1281
1265
1282
1266
ZVAL_COPY (& ch -> private_data , & source -> private_data );
@@ -2912,6 +2896,14 @@ PHP_FUNCTION(curl_close)
2912
2896
}
2913
2897
/* }}} */
2914
2898
2899
+ static void _php_curl_free_callback (php_curl_callback * callback )
2900
+ {
2901
+ if (callback ) {
2902
+ zval_ptr_dtor (& callback -> func_name );
2903
+ efree (callback );
2904
+ }
2905
+ }
2906
+
2915
2907
static void curl_free_obj (zend_object * object )
2916
2908
{
2917
2909
php_curl * ch = curl_from_obj (object );
@@ -2976,28 +2968,13 @@ static void curl_free_obj(zend_object *object)
2976
2968
efree (ch -> handlers .write_header );
2977
2969
efree (ch -> handlers .read );
2978
2970
2979
- if (ch -> handlers .progress ) {
2980
- zval_ptr_dtor (& ch -> handlers .progress -> func_name );
2981
- efree (ch -> handlers .progress );
2982
- }
2983
-
2971
+ _php_curl_free_callback (ch -> handlers .progress );
2984
2972
#if LIBCURL_VERSION_NUM >= 0x072000
2985
- if (ch -> handlers .xferinfo ) {
2986
- zval_ptr_dtor (& ch -> handlers .xferinfo -> func_name );
2987
- efree (ch -> handlers .xferinfo );
2988
- }
2973
+ _php_curl_free_callback (ch -> handlers .xferinfo );
2989
2974
#endif
2990
-
2991
- if (ch -> handlers .fnmatch ) {
2992
- zval_ptr_dtor (& ch -> handlers .fnmatch -> func_name );
2993
- efree (ch -> handlers .fnmatch );
2994
- }
2995
-
2975
+ _php_curl_free_callback (ch -> handlers .fnmatch );
2996
2976
#if LIBCURL_VERSION_NUM >= 0x075400
2997
- if (ch -> handlers .sshhostkey ) {
2998
- zval_ptr_dtor (& ch -> handlers .sshhostkey -> func_name );
2999
- efree (ch -> handlers .sshhostkey );
3000
- }
2977
+ _php_curl_free_callback (ch -> handlers .sshhostkey );
3001
2978
#endif
3002
2979
3003
2980
zval_ptr_dtor (& ch -> postfields );
0 commit comments