replace malloc with new, and free with delete, c++ style.