Fix segfault when fail on open on invalid mode