@@ -280,7 +280,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
280
280
int control_iscritical = 0 , rc = LDAP_SUCCESS ;
281
281
char * * ldap_attrs = NULL ;
282
282
LDAPSortKey * * sort_keys = NULL ;
283
- zend_string * tmpstring = NULL ;
283
+ zend_string * tmpstring = NULL , * * tmpstrings1 = NULL , * * tmpstrings2 = NULL ;
284
+ size_t num_tmpstrings1 = 0 , num_tmpstrings2 = 0 ;
284
285
285
286
if ((val = zend_hash_str_find (Z_ARRVAL_P (array ), "oid" , sizeof ("oid" ) - 1 )) == NULL ) {
286
287
php_error_docref (NULL , E_WARNING , "Control must have an oid key" );
@@ -394,7 +395,6 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
394
395
if (ber_flatten2 (vrber , control_value , 0 ) == -1 ) {
395
396
rc = -1 ;
396
397
}
397
- ber_free (vrber , 1 );
398
398
}
399
399
}
400
400
}
@@ -416,6 +416,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
416
416
417
417
num_attribs = zend_hash_num_elements (Z_ARRVAL_P (tmp ));
418
418
ldap_attrs = safe_emalloc ((num_attribs + 1 ), sizeof (char * ), 0 );
419
+ tmpstrings1 = safe_emalloc (num_attribs , sizeof (zend_string * ), 0 );
420
+ num_tmpstrings1 = 0 ;
419
421
420
422
for (i = 0 ; i < num_attribs ; i ++ ) {
421
423
if ((attr = zend_hash_index_find (Z_ARRVAL_P (tmp ), i )) == NULL ) {
@@ -424,12 +426,13 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
424
426
goto failure ;
425
427
}
426
428
427
- tmpstring = zval_get_string (attr );
429
+ tmpstrings1 [ num_tmpstrings1 ] = zval_get_string (attr );
428
430
if (EG (exception )) {
429
431
rc = -1 ;
430
432
goto failure ;
431
433
}
432
- ldap_attrs [i ] = ZSTR_VAL (tmpstring );
434
+ ldap_attrs [i ] = ZSTR_VAL (tmpstrings1 [num_tmpstrings1 ]);
435
+ ++ num_tmpstrings1 ;
433
436
}
434
437
ldap_attrs [num_attribs ] = NULL ;
435
438
@@ -454,6 +457,10 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
454
457
455
458
num_keys = zend_hash_num_elements (Z_ARRVAL_P (val ));
456
459
sort_keys = safe_emalloc ((num_keys + 1 ), sizeof (LDAPSortKey * ), 0 );
460
+ tmpstrings1 = safe_emalloc (num_keys , sizeof (zend_string * ), 0 );
461
+ tmpstrings2 = safe_emalloc (num_keys , sizeof (zend_string * ), 0 );
462
+ num_tmpstrings1 = 0 ;
463
+ num_tmpstrings2 = 0 ;
457
464
458
465
for (i = 0 ; i < num_keys ; i ++ ) {
459
466
if ((sortkey = zend_hash_index_find (Z_ARRVAL_P (val ), i )) == NULL ) {
@@ -468,20 +475,22 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
468
475
goto failure ;
469
476
}
470
477
sort_keys [i ] = emalloc (sizeof (LDAPSortKey ));
471
- tmpstring = zval_get_string (tmp );
478
+ tmpstrings1 [ num_tmpstrings1 ] = zval_get_string (tmp );
472
479
if (EG (exception )) {
473
480
rc = -1 ;
474
481
goto failure ;
475
482
}
476
- sort_keys [i ]-> attributeType = ZSTR_VAL (tmpstring );
483
+ sort_keys [i ]-> attributeType = ZSTR_VAL (tmpstrings1 [num_tmpstrings1 ]);
484
+ ++ num_tmpstrings1 ;
477
485
478
486
if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "oid" , sizeof ("oid" ) - 1 )) != NULL ) {
479
- tmpstring = zval_get_string (tmp );
487
+ tmpstrings2 [ num_tmpstrings2 ] = zval_get_string (tmp );
480
488
if (EG (exception )) {
481
489
rc = -1 ;
482
490
goto failure ;
483
491
}
484
- sort_keys [i ]-> orderingRule = ZSTR_VAL (tmpstring );
492
+ sort_keys [i ]-> orderingRule = ZSTR_VAL (tmpstrings2 [num_tmpstrings2 ]);
493
+ ++ num_tmpstrings2 ;
485
494
} else {
486
495
sort_keys [i ]-> orderingRule = NULL ;
487
496
}
@@ -588,6 +597,20 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
588
597
if (tmpstring != NULL ) {
589
598
zend_string_release (tmpstring );
590
599
}
600
+ if (tmpstrings1 != NULL ) {
601
+ int i ;
602
+ for (i = 0 ; i < num_tmpstrings1 ; ++ i ) {
603
+ zend_string_release (tmpstrings1 [i ]);
604
+ }
605
+ efree (tmpstrings1 );
606
+ }
607
+ if (tmpstrings2 != NULL ) {
608
+ int i ;
609
+ for (i = 0 ; i < num_tmpstrings2 ; ++ i ) {
610
+ zend_string_release (tmpstrings2 [i ]);
611
+ }
612
+ efree (tmpstrings2 );
613
+ }
591
614
if (control_value != NULL ) {
592
615
ber_memfree (control_value );
593
616
control_value = NULL ;
@@ -4207,6 +4230,11 @@ PHP_FUNCTION(ldap_exop_passwd)
4207
4230
lnewpw .bv_len > 0 ? & lnewpw : NULL ,
4208
4231
requestctrls ,
4209
4232
NULL , & msgid );
4233
+
4234
+ if (requestctrls != NULL ) {
4235
+ efree (requestctrls );
4236
+ }
4237
+
4210
4238
if (rc != LDAP_SUCCESS ) {
4211
4239
php_error_docref (NULL , E_WARNING , "Passwd modify extended operation failed: %s (%d)" , ldap_err2string (rc ), rc );
4212
4240
RETURN_FALSE ;
0 commit comments