fix a leak without introducing a warning

Same fix as bbb7b07332, using code @pjrobertson suggested.