fix potential crash accessing de-allocated temporary memory