Skip to content

Commit 4172eda

Browse files
author
Stig Venaas
committed
Fixed memory leak in ldap_first_attribute(), ldap_next_attribute(),
ldap_get_attributes(), ldap_get_dn() and ldap_dn2ufn() when using post RFC 1823 API. Still more leaks to fix.
1 parent 0873986 commit 4172eda

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

ext/ldap/ldap.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ PHP_FUNCTION(ldap_first_attribute)
997997
ZEND_REGISTER_RESOURCE(return_value, ber, le_ber_entry);
998998

999999
RETVAL_STRING(attribute,1);
1000-
#ifdef WINDOWS
1000+
#if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP || WINDOWS
10011001
ldap_memfree(attribute);
10021002
#endif
10031003
}
@@ -1028,7 +1028,7 @@ PHP_FUNCTION(ldap_next_attribute)
10281028
ZEND_REGISTER_RESOURCE(return_value, ber, le_ber_entry);
10291029

10301030
RETVAL_STRING(attribute,1);
1031-
#ifdef WINDOWS
1031+
#if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP || WINDOWS
10321032
ldap_memfree(attribute);
10331033
#endif
10341034
}
@@ -1075,8 +1075,15 @@ PHP_FUNCTION(ldap_get_attributes)
10751075
add_index_string(return_value, num_attrib, attribute, 1);
10761076

10771077
num_attrib++;
1078+
#if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP || WINDOWS
1079+
ldap_memfree(attribute);
1080+
#endif
10781081
attribute = ldap_next_attribute(ldap, ldap_result_entry, ber);
10791082
}
1083+
#if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP || WINDOWS
1084+
if (ber != NULL)
1085+
ber_free(ber, 0);
1086+
#endif
10801087

10811088
add_assoc_long(return_value, "count", num_attrib);
10821089
}
@@ -1185,7 +1192,7 @@ PHP_FUNCTION(ldap_get_dn)
11851192
text = ldap_get_dn(ldap, ldap_result_entry);
11861193
if ( text != NULL ) {
11871194
RETVAL_STRING(text,1);
1188-
#ifdef WINDOWS
1195+
#if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP || WINDOWS
11891196
ldap_memfree(text);
11901197
#endif
11911198
} else {
@@ -1245,7 +1252,7 @@ PHP_FUNCTION(ldap_dn2ufn)
12451252

12461253
if (ufn !=NULL) {
12471254
RETVAL_STRING(ufn,1);
1248-
#ifdef WINDOWS
1255+
#if ( LDAP_API_VERSION > 2000 ) || HAVE_NSLDAP || WINDOWS
12491256
ldap_memfree(ufn);
12501257
#endif
12511258
} else {

0 commit comments

Comments
 (0)