[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Segmentation fault in ldap_get_values()
I am using opnLDAP version 1.1.4
I am executing a small routine to extract attribute values for my result.
I have attached the code below.
It gives me segmentation fault while coming across malloc().
The position of segmentation fault is in function ber_get_stringa () in
file decode.c .
I am using the call ldap_get_values () that leads to SIGSEGV
The search returns about 200 entries. While extracting attribute names and
attribute values, the routine extracts about 6 entries successfully (all
attribute names and values) but faults at (about 7th entry)next entry and
that too while retrieving 8th attribute.
I am including my code as well as the output by gdb.
Any clues ?
Am I not greeing any pointers which I should have in my application
routine ?
I will be happy to provide more info on this.
Thanks
Himanshu
------------------------gdb shows this location ---------------
ber_get_stringa (ber=0xbffff8c8, buf=0x8053af0) at decode.c:234
234 if ( (*buf = (char *) malloc( (size_t)datalen + 1 )) ==
NULL )
(gdb)
Program received signal SIGSEGV, Segmentation fault.
0x40081414 in malloc ()
---------------------------END--------------------------------------
-------------------------my code-----------------------------------
if ( ldap_search_s( ld, SEARCHBASE, LDAP_SCOPE_SUBTREE, FILTER, NULL,
0, &result ) != LDAP_SUCCESS) {
ldap_perror ( ld, "ldap_searc_s");
exit(1);
}
for ( eachentry = ldap_first_entry( ld, result); eachentry != NULL;
eachentry = ldap_next_entry( ld, eachentry)) {
for ( attr = ldap_first_attribute( ld, eachentry, &ber );
attr != NULL;
attr = ldap_next_attribute( ld, eachentry, ber)) {
if ( (vals = ldap_get_values( ld, eachentry, attr )) != NULL ) {
for( i = 0; vals[i] != NULL; i++) {
printf( "%s = %s\n", attr, vals[i] );
}
ldap_value_free( vals);
}
}
if ( ber != NULL) {
ber_free(ber, 0);
}
}
ldap_msgfree(result);
ldap_unbind( ld );
return( 0);
----------------------------------------------END Code-----------