@@ -282,7 +282,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
282
282
int control_iscritical = 0 , rc = LDAP_SUCCESS ;
283
283
char * * ldap_attrs = NULL ;
284
284
LDAPSortKey * * sort_keys = NULL ;
285
- zend_string * tmpstring = NULL ;
285
+ zend_string * tmpstring = NULL , * * tmpstrings1 = NULL , * * tmpstrings2 = NULL ;
286
+ size_t num_tmpstrings1 = 0 , num_tmpstrings2 = 0 ;
286
287
287
288
if ((val = zend_hash_str_find (Z_ARRVAL_P (array ), "oid" , sizeof ("oid" ) - 1 )) == NULL ) {
288
289
php_error_docref (NULL , E_WARNING , "Control must have an oid key" );
@@ -396,7 +397,6 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
396
397
if (ber_flatten2 (vrber , control_value , 0 ) == -1 ) {
397
398
rc = -1 ;
398
399
}
399
- ber_free (vrber , 1 );
400
400
}
401
401
}
402
402
}
@@ -418,6 +418,8 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
418
418
419
419
num_attribs = zend_hash_num_elements (Z_ARRVAL_P (tmp ));
420
420
ldap_attrs = safe_emalloc ((num_attribs + 1 ), sizeof (char * ), 0 );
421
+ tmpstrings1 = safe_emalloc (num_attribs , sizeof (zend_string * ), 0 );
422
+ num_tmpstrings1 = 0 ;
421
423
422
424
for (i = 0 ; i < num_attribs ; i ++ ) {
423
425
if ((attr = zend_hash_index_find (Z_ARRVAL_P (tmp ), i )) == NULL ) {
@@ -426,12 +428,13 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
426
428
goto failure ;
427
429
}
428
430
429
- tmpstring = zval_get_string (attr );
431
+ tmpstrings1 [ num_tmpstrings1 ] = zval_get_string (attr );
430
432
if (EG (exception )) {
431
433
rc = -1 ;
432
434
goto failure ;
433
435
}
434
- ldap_attrs [i ] = ZSTR_VAL (tmpstring );
436
+ ldap_attrs [i ] = ZSTR_VAL (tmpstrings1 [num_tmpstrings1 ]);
437
+ ++ num_tmpstrings1 ;
435
438
}
436
439
ldap_attrs [num_attribs ] = NULL ;
437
440
@@ -456,6 +459,10 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
456
459
457
460
num_keys = zend_hash_num_elements (Z_ARRVAL_P (val ));
458
461
sort_keys = safe_emalloc ((num_keys + 1 ), sizeof (LDAPSortKey * ), 0 );
462
+ tmpstrings1 = safe_emalloc (num_keys , sizeof (zend_string * ), 0 );
463
+ tmpstrings2 = safe_emalloc (num_keys , sizeof (zend_string * ), 0 );
464
+ num_tmpstrings1 = 0 ;
465
+ num_tmpstrings2 = 0 ;
459
466
460
467
for (i = 0 ; i < num_keys ; i ++ ) {
461
468
if ((sortkey = zend_hash_index_find (Z_ARRVAL_P (val ), i )) == NULL ) {
@@ -470,20 +477,22 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
470
477
goto failure ;
471
478
}
472
479
sort_keys [i ] = emalloc (sizeof (LDAPSortKey ));
473
- tmpstring = zval_get_string (tmp );
480
+ tmpstrings1 [ num_tmpstrings1 ] = zval_get_string (tmp );
474
481
if (EG (exception )) {
475
482
rc = -1 ;
476
483
goto failure ;
477
484
}
478
- sort_keys [i ]-> attributeType = ZSTR_VAL (tmpstring );
485
+ sort_keys [i ]-> attributeType = ZSTR_VAL (tmpstrings1 [num_tmpstrings1 ]);
486
+ ++ num_tmpstrings1 ;
479
487
480
488
if ((tmp = zend_hash_str_find (Z_ARRVAL_P (sortkey ), "oid" , sizeof ("oid" ) - 1 )) != NULL ) {
481
- tmpstring = zval_get_string (tmp );
489
+ tmpstrings2 [ num_tmpstrings2 ] = zval_get_string (tmp );
482
490
if (EG (exception )) {
483
491
rc = -1 ;
484
492
goto failure ;
485
493
}
486
- sort_keys [i ]-> orderingRule = ZSTR_VAL (tmpstring );
494
+ sort_keys [i ]-> orderingRule = ZSTR_VAL (tmpstrings2 [num_tmpstrings2 ]);
495
+ ++ num_tmpstrings2 ;
487
496
} else {
488
497
sort_keys [i ]-> orderingRule = NULL ;
489
498
}
@@ -590,6 +599,20 @@ static int _php_ldap_control_from_array(LDAP *ld, LDAPControl** ctrl, zval* arra
590
599
if (tmpstring != NULL ) {
591
600
zend_string_release (tmpstring );
592
601
}
602
+ if (tmpstrings1 != NULL ) {
603
+ int i ;
604
+ for (i = 0 ; i < num_tmpstrings1 ; ++ i ) {
605
+ zend_string_release (tmpstrings1 [i ]);
606
+ }
607
+ efree (tmpstrings1 );
608
+ }
609
+ if (tmpstrings2 != NULL ) {
610
+ int i ;
611
+ for (i = 0 ; i < num_tmpstrings2 ; ++ i ) {
612
+ zend_string_release (tmpstrings2 [i ]);
613
+ }
614
+ efree (tmpstrings2 );
615
+ }
593
616
if (control_value != NULL ) {
594
617
ber_memfree (control_value );
595
618
control_value = NULL ;
@@ -4292,6 +4315,11 @@ PHP_FUNCTION(ldap_exop_passwd)
4292
4315
lnewpw .bv_len > 0 ? & lnewpw : NULL ,
4293
4316
requestctrls ,
4294
4317
NULL , & msgid );
4318
+
4319
+ if (requestctrls != NULL ) {
4320
+ efree (requestctrls );
4321
+ }
4322
+
4295
4323
if (rc != LDAP_SUCCESS ) {
4296
4324
php_error_docref (NULL , E_WARNING , "Passwd modify extended operation failed: %s (%d)" , ldap_err2string (rc ), rc );
4297
4325
RETURN_FALSE ;
0 commit comments