os_net fixes

fix memory leaks (in error branches) and check return values of library calls (see coverity)