More memory freeing patches to message.c
Steffen Ries
steffen.ries at sympatico.ca
Thu Jul 12 13:36:40 CEST 2001
Michael Ströder <michael at stroeder.com> writes:
> HI!
>
> Following some more advice by Stig Venaas (see message below) I've
> ifdef'ed some memory freeing calls provided by Steffen in message.c
> to keep the source compatible to OpenLDAP 1.2.x libs. I've attached
> my recent message.c.
>
> Backwards compability is not assumed to be crucial in the long run
> but seems nice if we can achieve it with fairly low efforts.
We need two changes to this version of 'message.c':
"ber_free(ber, 0)" needs to be called for API version 1.2.x too,
*except* when the ldap_next_attribute() has returned NULL. See the
complete patch against CVS below.
Looks like we are closing in now... :-)
/steffen
Index: message.c
===================================================================
RCS file: /cvsroot/python-ldap/python-ldap/Modules/message.c,v
retrieving revision 1.6
diff -u -w -r1.6 message.c
--- message.c 2000/08/18 00:21:46 1.6
+++ message.c 2001/07/12 11:31:00
@@ -51,7 +51,11 @@
if (attrdict == NULL) {
Py_DECREF(result);
ldap_msgfree( m );
+#if LDAP_API_VERSION >= 2000
+ ldap_memfree(dn);
+#else
free(dn);
+#endif
return NULL;
}
@@ -79,8 +83,15 @@
if (valuelist == NULL) {
Py_DECREF(attrdict);
Py_DECREF(result);
+ if (ber != NULL)
+ ber_free(ber, 0);
ldap_msgfree( m );
+#if LDAP_API_VERSION >= 2000
+ ldap_memfree(attr);
+ ldap_memfree(dn);
+#else
free(dn);
+#endif
return NULL;
}
@@ -97,8 +108,15 @@
Py_DECREF(result);
Py_DECREF(valuestr);
Py_DECREF(valuelist);
+ if (ber != NULL)
+ ber_free(ber, 0);
ldap_msgfree( m );
+#if LDAP_API_VERSION >= 2000
+ ldap_memfree(attr);
+ ldap_memfree(dn);
+#else
free(dn);
+#endif
return NULL;
}
Py_DECREF(valuestr);
@@ -106,14 +124,59 @@
ldap_value_free_len(bvals);
}
Py_DECREF( valuelist );
+#if LDAP_API_VERSION >= 2000
+ ldap_memfree(attr);
+#endif
}
entrytuple = Py_BuildValue("(sO)", dn, attrdict);
+#if LDAP_API_VERSION >= 2000
+ ldap_memfree(dn);
+#else
free(dn);
+#endif
Py_DECREF(attrdict);
PyList_Append(result, entrytuple);
Py_DECREF(entrytuple);
+#if ( LDAP_API_VERSION > 2000 )
+ if (ber != NULL)
+ ber_free(ber, 0);
+#endif
+ }
+#if LDAP_API_VERSION >= 2000
+ for(entry = ldap_first_reference(ld,m);
+ entry != NULL;
+ entry = ldap_next_reference(ld,entry))
+ {
+ char **refs = NULL;
+ PyObject* entrytuple;
+ PyObject* reflist = PyList_New(0);
+
+ if (reflist == NULL) {
+ Py_DECREF(result);
+ ldap_msgfree( m );
+ return NULL;
+ }
+ if (ldap_parse_reference(ld, entry, &refs, NULL, 0) != LDAP_SUCCESS) {
+ Py_DECREF(result);
+ ldap_msgfree( m );
+ return LDAPerror( ld, "ldap_parse_reference" );
+ }
+ if (refs) {
+ int i;
+ for (i=0; refs[i] != NULL; i++) {
+ PyObject *refstr = PyString_FromString(refs[i]);
+ PyList_Append(reflist, refstr);
+ Py_DECREF(refstr);
+ }
+ ber_memvfree( (void **) refs );
+ }
+ entrytuple = Py_BuildValue("(sO)", NULL, reflist);
+ Py_DECREF(reflist);
+ PyList_Append(result, entrytuple);
+ Py_DECREF(entrytuple);
}
+#endif
ldap_msgfree( m );
return result;
}
--
steffen.ries at sympatico.ca <> Gravity is a myth -- the Earth sucks!
More information about the python-ldap
mailing list