fix the identical leak in three different files.
reported by Brent Cook, original diff by logan
simplify and unobfuscate a variable to fix a mem leak.
original diff by logan