Fix memory leak in system