Fixed random memory leak and crash.