Pdb valgring issues

Fix all valgrind issues correspond to pdb.
Also it may fixs issue #1631.