fix memory leak in normalize function