@@ -278,7 +278,7 @@ static void _php_ldap_control_to_array(LDAP *ld, LDAPControl* ctrl, zval* array,
278
278
static int _php_ldap_control_from_array (LDAP * ld , LDAPControl * * ctrl , zval * array )
279
279
{
280
280
zval * val ;
281
- zend_string * control_oid = NULL ;
281
+ zend_string * control_oid ;
282
282
int control_iscritical = 0 , rc = LDAP_SUCCESS ;
283
283
char * * ldap_attrs = NULL ;
284
284
LDAPSortKey * * sort_keys = NULL ;
@@ -311,7 +311,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
311
311
} else {
312
312
tmpstring = zval_get_string (val );
313
313
if (EG (exception )) {
314
- return -1 ;
314
+ rc = -1 ;
315
+ goto failure ;
315
316
}
316
317
control_value -> bv_val = ZSTR_VAL (tmpstring );
317
318
control_value -> bv_len = ZSTR_LEN (tmpstring );
@@ -368,6 +369,7 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
368
369
php_error_docref (NULL , E_WARNING , "Failed to create assert control value: %s (%d)" , ldap_err2string (rc ), rc );
369
370
}
370
371
}
372
+ zend_string_release (assert );
371
373
}
372
374
} else if (strcmp (ZSTR_VAL (control_oid ), LDAP_CONTROL_VALUESRETURNFILTER ) == 0 ) {
373
375
zval * tmp ;
@@ -584,6 +586,10 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
584
586
}
585
587
586
588
failure :
589
+ zend_string_release (control_oid );
590
+ if (tmpstring != NULL ) {
591
+ zend_string_release (tmpstring );
592
+ }
587
593
if (control_value != NULL ) {
588
594
ber_memfree (control_value );
589
595
control_value = NULL ;
@@ -1462,7 +1468,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1462
1468
{
1463
1469
zval * link , * base_dn , * filter , * attrs = NULL , * attr , * serverctrls = NULL ;
1464
1470
zend_long attrsonly , sizelimit , timelimit , deref ;
1465
- zend_string * ldap_filter = NULL , * ldap_base_dn = NULL , * tmpstring ;
1471
+ zend_string * ldap_filter = NULL , * ldap_base_dn = NULL ;
1466
1472
char * * ldap_attrs = NULL ;
1467
1473
ldap_linkdata * ld = NULL ;
1468
1474
LDAPMessage * ldap_res ;
@@ -1471,7 +1477,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1471
1477
int old_ldap_sizelimit = -1 , old_ldap_timelimit = -1 , old_ldap_deref = -1 ;
1472
1478
int num_attribs = 0 , ret = 1 , i , errno , argcount = ZEND_NUM_ARGS ();
1473
1479
1474
- if (zend_parse_parameters (argcount , "zzz|alllla" , & link , & base_dn , & filter , & attrs , & attrsonly ,
1480
+ if (zend_parse_parameters (argcount , "zzz|alllla/ " , & link , & base_dn , & filter , & attrs , & attrsonly ,
1475
1481
& sizelimit , & timelimit , & deref , & serverctrls ) == FAILURE ) {
1476
1482
return ;
1477
1483
}
@@ -1498,12 +1504,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1498
1504
goto cleanup ;
1499
1505
}
1500
1506
1501
- tmpstring = zval_get_string (attr );
1507
+ convert_to_string (attr );
1502
1508
if (EG (exception )) {
1503
1509
ret = 0 ;
1504
1510
goto cleanup ;
1505
1511
}
1506
- ldap_attrs [i ] = ZSTR_VAL ( tmpstring );
1512
+ ldap_attrs [i ] = Z_STRVAL_P ( attr );
1507
1513
}
1508
1514
ldap_attrs [num_attribs ] = NULL ;
1509
1515
default :
@@ -1686,6 +1692,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope)
1686
1692
/* Restoring previous options */
1687
1693
php_set_opts (ld -> link , old_ldap_sizelimit , old_ldap_timelimit , old_ldap_deref , & ldap_sizelimit , & ldap_timelimit , & ldap_deref );
1688
1694
}
1695
+ if (ldap_filter ) {
1696
+ zend_string_release (ldap_filter );
1697
+ }
1698
+ if (ldap_base_dn ) {
1699
+ zend_string_release (ldap_base_dn );
1700
+ }
1689
1701
if (ldap_attrs != NULL ) {
1690
1702
efree (ldap_attrs );
1691
1703
}
@@ -2219,7 +2231,7 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
2219
2231
int i , j , num_attribs , num_values , msgid ;
2220
2232
size_t dn_len ;
2221
2233
int * num_berval ;
2222
- zend_string * attribute , * tmpstring ;
2234
+ zend_string * attribute ;
2223
2235
zend_ulong index ;
2224
2236
int is_full_add = 0 ; /* flag for full add operation so ldap_mod_add can be put back into oper, gerrit THomson */
2225
2237
@@ -2280,14 +2292,14 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
2280
2292
2281
2293
/* allow for arrays with one element, no allowance for arrays with none but probably not required, gerrit thomson. */
2282
2294
if ((num_values == 1 ) && (Z_TYPE_P (value ) != IS_ARRAY )) {
2283
- tmpstring = zval_get_string (value );
2295
+ convert_to_string (value );
2284
2296
if (EG (exception )) {
2285
2297
RETVAL_FALSE ;
2286
2298
goto cleanup ;
2287
2299
}
2288
2300
ldap_mods [i ]-> mod_bvalues [0 ] = (struct berval * ) emalloc (sizeof (struct berval ));
2289
- ldap_mods [i ]-> mod_bvalues [0 ]-> bv_val = ZSTR_VAL ( tmpstring );
2290
- ldap_mods [i ]-> mod_bvalues [0 ]-> bv_len = ZSTR_LEN ( tmpstring );
2301
+ ldap_mods [i ]-> mod_bvalues [0 ]-> bv_val = Z_STRVAL_P ( value );
2302
+ ldap_mods [i ]-> mod_bvalues [0 ]-> bv_len = Z_STRLEN_P ( value );
2291
2303
} else {
2292
2304
for (j = 0 ; j < num_values ; j ++ ) {
2293
2305
if ((ivalue = zend_hash_index_find (Z_ARRVAL_P (value ), j )) == NULL ) {
@@ -2297,14 +2309,14 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper, int ext)
2297
2309
RETVAL_FALSE ;
2298
2310
goto cleanup ;
2299
2311
}
2300
- tmpstring = zval_get_string (ivalue );
2312
+ convert_to_string (ivalue );
2301
2313
if (EG (exception )) {
2302
2314
RETVAL_FALSE ;
2303
2315
goto cleanup ;
2304
2316
}
2305
2317
ldap_mods [i ]-> mod_bvalues [j ] = (struct berval * ) emalloc (sizeof (struct berval ));
2306
- ldap_mods [i ]-> mod_bvalues [j ]-> bv_val = ZSTR_VAL ( tmpstring );
2307
- ldap_mods [i ]-> mod_bvalues [j ]-> bv_len = ZSTR_LEN ( tmpstring );
2318
+ ldap_mods [i ]-> mod_bvalues [j ]-> bv_val = Z_STRVAL_P ( ivalue );
2319
+ ldap_mods [i ]-> mod_bvalues [j ]-> bv_len = Z_STRLEN_P ( ivalue );
2308
2320
}
2309
2321
}
2310
2322
ldap_mods [i ]-> mod_bvalues [num_values ] = NULL ;
@@ -2829,6 +2841,7 @@ PHP_FUNCTION(ldap_modify_batch)
2829
2841
/* fill it */
2830
2842
ldap_mods [i ]-> mod_bvalues [j ]-> bv_len = ZSTR_LEN (modval );
2831
2843
ldap_mods [i ]-> mod_bvalues [j ]-> bv_val = estrndup (ZSTR_VAL (modval ), ZSTR_LEN (modval ));
2844
+ zend_string_release (modval );
2832
2845
}
2833
2846
2834
2847
/* NULL-terminate values */
@@ -3332,8 +3345,10 @@ PHP_FUNCTION(ldap_set_option)
3332
3345
RETURN_FALSE ;
3333
3346
}
3334
3347
if (ldap_set_option (ldap , option , ZSTR_VAL (val ))) {
3348
+ zend_string_release (val );
3335
3349
RETURN_FALSE ;
3336
3350
}
3351
+ zend_string_release (val );
3337
3352
} break ;
3338
3353
/* options with boolean value */
3339
3354
case LDAP_OPT_REFERRALS :
0 commit comments