Fix some memory leaks.
Fix some memory leaks(2).
Change run_mode to int, added to default parameter.