Fix some leaks, remove exit() calls, fix incorrect scoped_ptr usage.  Scoped_ptr calls delete under the hood, so using .reset() with malloc will cause both a leak and a memory allocation lib mis-match, resulting in undefined behavior.  Exit calls should never be used inside an application; it causes the entire app to stop running.