Fix memory leak and NSError generally code.
Merge pull request #2 from r-plus/FixMemoryLeak

Fix memory leak and NSError generally code.