aOneString = (char*) malloc((sizeof(username)+1));
strcpy(aOneString, username);
strcat(aOneString, ":");
strcat(aOneString, realm);
strcat(aOneString, ":");
strcat(aOneString, password);
You allocate exactly enough space to hold username, then you write username, a colon, realm, another colon, and password to that space. How do you expect all that to fit?