fix bug of memory leak

change malloc() free() to more stable new() and delete []