The original code allocates an array of characters on the stack inside an inner block, then keeps a pointer to the array that lives beyond the lifetime of the inner block. Later accesses to the array via the pointer see junk bytes.