Actually enable memory-checking code when in debug mode

(it was checking the wrong flag, so probably never enabled)
(cherry picked from commit 69e4fd8e65258f0feae719bf571af4faf0839a61)