Made connect functions return NULL on alloc failures.

Updated documentation and examples accordingly.