+void
+ldap_free_request( LDAP *ld, LDAPRequest *lr )
+{
+ LDAPRequest **ttmplr;
+
+#ifdef NEW_LOGGING
+ LDAP_LOG (( "request", LDAP_LEVEL_ARGS,
+ "ldap_free_request (origid %d, msgid %d)\n",
+ lr->lr_origid, lr->lr_msgid ));
+#else
+ Debug( LDAP_DEBUG_TRACE, "ldap_free_request (origid %d, msgid %d)\n",
+ lr->lr_origid, lr->lr_msgid, 0 );
+#endif
+
+ if ( lr->lr_parent != NULL ) {
+ --lr->lr_parent->lr_outrefcnt;
+ for ( ttmplr = &lr->lr_parent->lr_child; *ttmplr && *ttmplr != lr; ttmplr = &(*ttmplr)->lr_refnext );
+ if ( *ttmplr == lr )
+ *ttmplr = lr->lr_refnext;
+ } else {
+ /* free all referrals (child requests) */
+ while ( lr->lr_child )
+ ldap_free_request( ld, lr->lr_child );
+ }
+ ldap_free_request_int( ld, lr );
+}
+
+