Fix data loss on platforms with 32-bit long.
Fix a memory leak.