Fixed errors freeing already freed pointer