lib: added additional checks to socket.cc to avoid using a null device object