Replace malloc with calloc; now connects successfully