libmemif: prevent crash in case of invalid connection handle