@@ -283,7 +283,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
283
283
int control_iscritical = 0 , rc = LDAP_SUCCESS ;
284
284
char * * ldap_attrs = NULL ;
285
285
LDAPSortKey * * sort_keys = NULL ;
286
- zend_string * tmpstring = NULL ;
286
+ zend_string * tmpstring = NULL , * * tmpstrings1 = NULL , * * tmpstrings2 = NULL ;
287
+ size_t num_tmpstrings1 = 0 , num_tmpstrings2 = 0 ;
287
288
288
289
if ((val = zend_hash_str_find (Z_ARRVAL_P (array ), "oid" , sizeof ("oid" ) - 1 )) == NULL ) {
289
290
php_error_docref (NULL , E_WARNING , "Control must have an oid key" );
@@ -397,7 +398,6 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
397
398
if (ber_flatten2 (vrber , control_value , 0 ) == -1 ) {
398
399
rc = -1 ;
399
400
}
400
- ber_free (vrber , 1 );
401
401
}
402
402
}
403
403
}
@@ -419,6 +419,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
419
419
420
420
num_attribs = zend_hash_num_elements (Z_ARRVAL_P (tmp ));
421
421
ldap_attrs = safe_emalloc ((num_attribs + 1 ), sizeof (char * ), 0 );
422
+ tmpstrings1 = safe_emalloc (num_attribs , sizeof (zend_string * ), 0 );
423
+ num_tmpstrings1 = 0 ;
422
424
423
425
for (i = 0 ; i < num_attribs ; i ++ ) {
424
426
if ((attr = zend_hash_index_find (Z_ARRVAL_P (tmp ), i )) == NULL ) {
@@ -427,12 +429,13 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
427
429
goto failure ;
428
430
}
429
431
430
- tmpstring = zval_get_string (attr );
432
+ tmpstrings1 [ num_tmpstrings1 ] = zval_get_string (attr );
431
433
if (EG (exception )) {
432
434
rc = -1 ;
433
435
goto failure ;
434
436
}
435
- ldap_attrs [i ] = ZSTR_VAL (tmpstring );
437
+ ldap_attrs [i ] = ZSTR_VAL (tmpstrings1 [num_tmpstrings1 ]);
438
+ ++ num_tmpstrings1 ;
436
439
}
437
440
ldap_attrs [num_attribs ] = NULL ;
438
441
@@ -457,6 +460,10 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
457
460
458
461
num_keys = zend_hash_num_elements (Z_ARRVAL_P (val ));
459
462
sort_keys = safe_emalloc ((num_keys + 1 ), sizeof (LDAPSortKey * ), 0 );
463
+ tmpstrings1 = safe_emalloc (num_keys , sizeof (zend_string * ), 0 );
464
+ tmpstrings2 = safe_emalloc (num_keys , sizeof (zend_string * ), 0 );
465
+ num_tmpstrings1 = 0 ;
466
+ num_tmpstrings2 = 0 ;
460
467
461
468
for (i = 0 ; i < num_keys ; i ++ ) {
462
469
if ((sortkey = zend_hash_index_find (Z_ARRVAL_P (val ), i )) == NULL ) {
@@ -471,20 +478,22 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
471
478
goto failure ;
472
479
}
473
480
sort_keys [i ] = emalloc (sizeof (LDAPSortKey ));
474
- tmpstring = zval_get_string (tmp );
481
+ tmpstrings1 [ num_tmpstrings1 ] = zval_get_string (tmp );
475
482
if (EG (exception )) {
476
483
rc = -1 ;
477
484
goto failure ;
478
485
}
479
- sort_keys [i ]-> attributeType = ZSTR_VAL (tmpstring );
486
+ sort_keys [i ]-> attributeType = ZSTR_VAL (tmpstrings1 [num_tmpstrings1 ]);
487
+ ++ num_tmpstrings1 ;
480
488
481
489
if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "oid" , sizeof ("oid" ) - 1 )) != NULL ) {
482
- tmpstring = zval_get_string (tmp );
490
+ tmpstrings2 [ num_tmpstrings2 ] = zval_get_string (tmp );
483
491
if (EG (exception )) {
484
492
rc = -1 ;
485
493
goto failure ;
486
494
}
487
- sort_keys [i ]-> orderingRule = ZSTR_VAL (tmpstring );
495
+ sort_keys [i ]-> orderingRule = ZSTR_VAL (tmpstrings2 [num_tmpstrings2 ]);
496
+ ++ num_tmpstrings2 ;
488
497
} else {
489
498
sort_keys [i ]-> orderingRule = NULL ;
490
499
}
@@ -591,6 +600,20 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
591
600
if (tmpstring != NULL ) {
592
601
zend_string_release (tmpstring );
593
602
}
603
+ if (tmpstrings1 != NULL ) {
604
+ int i ;
605
+ for (i = 0 ; i < num_tmpstrings1 ; ++ i ) {
606
+ zend_string_release (tmpstrings1 [i ]);
607
+ }
608
+ efree (tmpstrings1 );
609
+ }
610
+ if (tmpstrings2 != NULL ) {
611
+ int i ;
612
+ for (i = 0 ; i < num_tmpstrings2 ; ++ i ) {
613
+ zend_string_release (tmpstrings2 [i ]);
614
+ }
615
+ efree (tmpstrings2 );
616
+ }
594
617
if (control_value != NULL ) {
595
618
ber_memfree (control_value );
596
619
control_value = NULL ;
@@ -3438,6 +3461,7 @@ PHP_FUNCTION(ldap_parse_result)
3438
3461
/* Reverse -> fall through */
3439
3462
switch (myargcount ) {
3440
3463
case 7 :
3464
+ zval_ptr_dtor (serverctrls );
3441
3465
_php_ldap_controls_to_array (ld -> link , lserverctrls , serverctrls , 0 );
3442
3466
case 6 :
3443
3467
zval_ptr_dtor (referrals );
@@ -4327,6 +4351,11 @@ PHP_FUNCTION(ldap_exop_passwd)
4327
4351
lnewpw .bv_len > 0 ? & lnewpw : NULL ,
4328
4352
requestctrls ,
4329
4353
NULL , & msgid );
4354
+
4355
+ if (requestctrls != NULL ) {
4356
+ efree (requestctrls );
4357
+ }
4358
+
4330
4359
if (rc != LDAP_SUCCESS ) {
4331
4360
php_error_docref (NULL , E_WARNING , "Passwd modify extended operation failed: %s (%d)" , ldap_err2string (rc ), rc );
4332
4361
RETURN_FALSE ;
@@ -4366,6 +4395,7 @@ PHP_FUNCTION(ldap_exop_passwd)
4366
4395
}
4367
4396
4368
4397
if (myargcount > 4 ) {
4398
+ zval_ptr_dtor (serverctrls );
4369
4399
_php_ldap_controls_to_array (ld -> link , lserverctrls , serverctrls , 0 );
4370
4400
}
4371
4401
0 commit comments