Fix an inverted-check bug, found with valgrind