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

Core dumped!?



Hi:
     I have to ask the same question I refered some days ago for I am
 too...too confusion.I still couldn't resolve the mistake about memory 
 dumping.As soon as my program run to the API "ldap_add_s" the os report
 "memory default,core dumped".
     My program is very simple and I used the debugger "dbx" to check
 all the variable. In my program I only use these API: ldap_open,
 ldap_simple_bind_s,ldap_add_s,ldap_unbind.The destination of my program
 is to add a entry named "cn=rjy3,o=university of michigan,c=us" with 
 two attributes:objecclass and cn.I copy it below and hope any persons 
 who ever used these API to develop projects take some time to check it.
 I can't express my nervousness and appreciation in words.
 Thanks in advance!

 ****************** source of my program********************
 #include "portable.h"
 #include <alloca.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

 #include <ac/ctype.h>
 #include <ac/signal.h>
 #include <ac/socket.h>
 #include <ac/string.h>
 #include <ac/time.h>
 #include <ac/unistd.h>

 #include <lber.h>
 #include <ldap.h>
 #include <ldif.h>

 #include "ldapconfig.h"


  main()
    {
            LDAP            *ld;
            char            *binddn="cn=manager,o=university of michigan,c=us";
            char            *pwd="secret";
            char            *temp;
            char            *temp2;
            LDAPMod         *attr1[4];
            LDAPMod         *attr;
            char            *adddn="cn=rjy3,o=universsity of michigan,c=us\0";
                      /* open a connection */
            if ( (ld = ldap_open( "alpha433.nudt.edu.cn", LDAP_PORT ))
                    == NULL )
               {    printf("can't connect the server\n");
                    exit( 1 );
               }
            printf("connection is opened success\n");  // debug
            if(ldap_simple_bind_s(ld,binddn,pwd)!=LDAP_SUCCESS)
            { ldap_perror(ld,"ldap_simple_bind_s"); exit(1);
            } 
            attr=(LDAPMod *)malloc(sizeof(LDAPMod)*3);
            attr[0].mod_op=0;
            attr[0].mod_type=strdup("objectcalss");
            attr[0].mod_values=(char **)malloc(sizeof(char *)*2);
            attr[0].mod_values[0]=strdup("person");
            attr[0].mod_values[1]=NULL;
            /*             */
            attr[1].mod_op=0;
            attr[1].mod_type=strdup("cn\0");
            attr[1].mod_values=(char **)malloc(sizeof(char *)*2);
            attr[1].mod_values[0]=strdup("rjy3\0");
            attr[1].mod_values[1]=NULL;
           /*              */
            attr1[0]=&attr[0];
            attr1[1]=&attr[1];
            attr1[2]=NULL;
           /*               */
           printf("begin add entry rjy\n");
           if(ldap_add_s(ld,adddn,attr1)==LDAP_SUCCESS)
            {  printf("You may search the new entry\n");
            }
            else
            {ldap_perror(" can't perform the add operation\nldap_add_s:");
            }
            ldap_mods_free(attr1,1);          
         
            /* close and free connection resources */
            ldap_unbind( ld );
    }

_____________________________________________
Ê׶¼ÔÚÏß--ÏȽøÖйúÈ˵ÄÍøÉϼÒÔ° http://www.263.net
Ãâ·ÑÓÊÏä ÓʼþÔÓÖ¾ Ç©ÃûÓʼþ Óʼþ¼ÓÃÜ Óʼþ×·Éíºô
ËÑË÷ÒýÇæ ¸öÈËÕ¾µã ÔÚÏßÓÎÏ· ÍøÉÏÁÄÌì ÍøÉϹҺÅ
½ðÈÚÍõ¹ú ÔÚÏßɱ¶¾ ÌøÔéÊг¡ Èí¼þÏÂÔØ ÐÝÏÐÓéÀÖ