fix err handle&all possible mem leaks with it fix