Pdb valgrind issue

Fix some memory issues + may be it fixed #1631