On a CentOS 6.6 server the following code compiles (with gcc version 4.4.7 or with clang version 3.4.2) without incident but results in a segmentation fault when run:
#include <ldap.h>
int main( int argc, char **argv )
{
LDAPURLDesc **ludpp;
int parse_status = ldap_url_parse("ldap://ldap.example.com", ludpp);
char * str;
}
However if I modify it to remove the string declaration, like so:
#include <ldap.h>
int main( int argc, char **argv )
{
LDAPURLDesc **ludpp;
int parse_status = ldap_url_parse("ldap://ldap.example.com", ludpp);
}
then it runs without incident as well. On my Mac OS X 10.10.3 (Yosemite) both versions (with and without the string declaration) compile and run.
My three questions are:
- Why does the first example segfault on the CentOS server?
- Why does the second example NOT segfault on the CentOS server?
- What, specifically, is the difference between my Mac laptop and the Linux server that causes this disparity between the two?