From: Stig Venaas Date: Sat, 13 Jan 2001 10:00:27 +0000 (+0000) Subject: Fixed memory leaks that could happen in some error situations. Also removed X-Git-Tag: php-4.0.5RC1~607 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d9f52a417674fa0f403cf25ea85240649fa2eb47;p=php Fixed memory leaks that could happen in some error situations. Also removed some unnecessary code in ldap_set_option() --- diff --git a/ext/ldap/ldap.c b/ext/ldap/ldap.c index b360cee7f4..88e3c15ae4 100644 --- a/ext/ldap/ldap.c +++ b/ext/ldap/ldap.c @@ -660,6 +660,7 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) for(i=0; ivalue.ht, i, (void **) &attr) == FAILURE) { php_error(E_WARNING, "LDAP: Array initialization wrong"); + efree(ldap_attrs); RETURN_FALSE; } @@ -778,7 +779,12 @@ static void php_ldap_do_search(INTERNAL_FUNCTION_PARAMETERS, int scope) } ldap = _get_ldap_link(link); - if (ldap == NULL) RETURN_FALSE; + if (ldap == NULL) { + if (ldap_attrs != NULL) { + efree(ldap_attrs); + } + RETURN_FALSE; + } php_set_opts(ldap, ldap_sizelimit, ldap_timelimit, ldap_deref); @@ -1387,6 +1393,12 @@ static void php_ldap_do_modify(INTERNAL_FUNCTION_PARAMETERS, int oper) ldap_mods[i]->mod_type = estrdup(attribute); } else { php_error(E_ERROR, "LDAP: Unknown Attribute in the data"); + /* Free allocated memory */ + while (i >= 0) { + efree(ldap_mods[i--]); + } + efree(num_berval); + efree(ldap_mods); RETURN_FALSE; } @@ -1770,9 +1782,6 @@ PHP_FUNCTION(ldap_set_option) { RETURN_FALSE; } ctrls = emalloc((1 + ncontrols) * sizeof(*ctrls)); - if (ctrls == NULL) { - RETURN_FALSE; - } *ctrls = NULL; ctrlp = ctrls; zend_hash_internal_pointer_reset(Z_ARRVAL_PP(newval)); @@ -1781,7 +1790,6 @@ PHP_FUNCTION(ldap_set_option) { php_error(E_WARNING, "The array value must contain only arrays, where each array is a control"); error = 1; break; - RETURN_FALSE; } if (zend_hash_find(Z_ARRVAL_PP(ctrlval), "oid", sizeof("oid"), (void **) &val) == FAILURE) { php_error(E_WARNING, "Control must have an oid key"); @@ -1789,10 +1797,6 @@ PHP_FUNCTION(ldap_set_option) { break; } ctrl = *ctrlp = emalloc(sizeof(**ctrlp)); - if (ctrl == NULL) { - error = 1; - break; - } convert_to_string_ex(val); ctrl->ldctl_oid = Z_STRVAL_PP(val); if (zend_hash_find(Z_ARRVAL_PP(ctrlval), "value", sizeof("value"), (void **) &val) == SUCCESS) {