Fixed a memory leak.

Added an exception framework to plug the leak.