added curl function, fixed early memory relase bug