From: Steffen R. <ste...@sy...> - 2001-07-12 11:36:48
|
Michael Str=F6der <mi...@st...> writes: > HI! >=20 > 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. >=20 > 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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 =3D=3D NULL) { Py_DECREF(result); ldap_msgfree( m ); +#if LDAP_API_VERSION >=3D 2000 + ldap_memfree(dn); +#else free(dn); +#endif return NULL; } =20 @@ -79,8 +83,15 @@ if (valuelist =3D=3D NULL) { Py_DECREF(attrdict); Py_DECREF(result); + if (ber !=3D NULL) + ber_free(ber, 0); ldap_msgfree( m ); +#if LDAP_API_VERSION >=3D 2000 + ldap_memfree(attr); + ldap_memfree(dn); +#else free(dn); +#endif return NULL; } =20 @@ -97,8 +108,15 @@ Py_DECREF(result); Py_DECREF(valuestr); Py_DECREF(valuelist); + if (ber !=3D NULL) + ber_free(ber, 0); ldap_msgfree( m ); +#if LDAP_API_VERSION >=3D 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 >=3D 2000 + ldap_memfree(attr); +#endif } =20 entrytuple =3D Py_BuildValue("(sO)", dn, attrdict); +#if LDAP_API_VERSION >=3D 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 !=3D NULL) + ber_free(ber, 0); +#endif + } +#if LDAP_API_VERSION >=3D 2000 + for(entry =3D ldap_first_reference(ld,m); + entry !=3D NULL; + entry =3D ldap_next_reference(ld,entry)) + { + char **refs =3D NULL; + PyObject* entrytuple; + PyObject* reflist =3D PyList_New(0); + + if (reflist =3D=3D NULL) { + Py_DECREF(result); + ldap_msgfree( m ); + return NULL; + } + if (ldap_parse_reference(ld, entry, &refs, NULL, 0) !=3D LDAP_SUCCESS) { + Py_DECREF(result); + ldap_msgfree( m ); + return LDAPerror( ld, "ldap_parse_reference" ); + } + if (refs) { + int i; + for (i=3D0; refs[i] !=3D NULL; i++) { + PyObject *refstr =3D PyString_FromString(refs[i]); + PyList_Append(reflist, refstr); + Py_DECREF(refstr); + } + ber_memvfree( (void **) refs ); + } + entrytuple =3D Py_BuildValue("(sO)", NULL, reflist); + Py_DECREF(reflist); + PyList_Append(result, entrytuple); + Py_DECREF(entrytuple); } +#endif ldap_msgfree( m ); return result; } --=20 ste...@sy... <> Gravity is a myth -- the Earth sucks! |