Add malloc failure checks

In `ns_connect` and `ns_bind`