Fixed critical bug: memory leak when the callback throws an exception.