[Date Prev][Date Next] [Chronological] [Thread] [Top]

memory leak when chasing referrals?



Hello list,

I'm not 100% sure that this is a bug in OpenLDAP or in my code so I'll
post here first. I run into a memory leak when running the code below on
a server that contains referrals. The code itself is the minimal
representation I could make that triggers the leak.

The referral I used is something like:

dn: ou=ref,ou=people,dc=test,dc=tld
objectClass: referral
objectClass: extensibleObject
dc: subtree
ref: ldap://otherserver/ou=morepeople,dc=test2,dc=tld
ou: ref

When I run the code through "valgrind --leak-check=full" I get:

==30395== 4,184 (80 direct, 4,104 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 3
==30395==    at 0x402328F: calloc (vg_replace_malloc.c:467)
==30395==    by 0x41D2CDF: ber_memcalloc_x (in /usr/lib/liblber-2.4.so.2.5.6)
==30395==    by 0x40650A0: ldap_send_server_request (in /usr/lib/libldap_r-2.4.so.2.5.6)
==30395==    by 0x4065EB1: ldap_chase_v3referrals (in /usr/lib/libldap_r-2.4.so.2.5.6)
==30395==    by 0x40510A3: ldap_result (in /usr/lib/libldap_r-2.4.so.2.5.6)
==30395==    by 0x8048871: main (test.c:28)

Is there something wrong with my code (except for the complete lack of
error handling that I stripped out to improve readability)? Should I
free something in the LDAP_RES_SEARCH_REFERENCE case?

Thanks.

-----8<-- test.c --8<-----

#include <stdio.h>
#include <errno.h>

#define LDAP_DEPRECATED 1
#include <ldap.h>

int main(int argc,char *argv[])
{
  char *base="dc=test,dc=tld";
  char *filter="(objectClass=posixAccount)";
  char *attrs[] = { "uid", NULL };
  int i;
  LDAP *ld;
  LDAPMessage *msg=NULL;
  int msgid;
  char **values;
  /* set up connection */
  ldap_initialize(&ld,"ldap://localhost";);
  i=3;
  ldap_set_option(ld,LDAP_OPT_PROTOCOL_VERSION,&i);
  ldap_simple_bind_s(ld,NULL,NULL);
  /* start search and handle results */
  ldap_search_ext(ld,base,LDAP_SCOPE_SUB,filter,attrs,
                  0,NULL,NULL,NULL,LDAP_NO_LIMIT,&msgid);
  while (1)
  {
    switch (ldap_result(ld,msgid,LDAP_MSG_ONE,NULL,&msg))
    {
      case LDAP_RES_SEARCH_ENTRY:
        /* we have a normal search entry, print some attribute values */
        values=ldap_get_values(ld,msg,attrs[0]);
        for (i=0;values[i]!=NULL;i++)
          fprintf(stderr,"%s=%s\n",attrs[0],values[i]);
        ldap_value_free(values);
        break;
      case LDAP_RES_SEARCH_RESULT:
        /* end of results */
        ldap_msgfree(msg);
        ldap_unbind(ld);
        return 0;
      case LDAP_RES_SEARCH_REFERENCE:
        break; /* just ignore search references */
      default:
        /* we have some error condition, bail out */
        return -1;
    }
    ldap_msgfree(msg);
  }
}

-----8<-- test.c --8<-----

-- 
-- arthur - arthur@arthurdejong.org - http://arthurdejong.org --

Attachment: signature.asc
Description: This is a digitally signed message part