add a memory test
fix memory leaks
use a global location
the loop should terminate.
fix the compile error under linux amd64
Merge branch 'original'
fix memory crash