From 7ac0904a1fa8260ad0176522ee9d99bdfc602f27 Mon Sep 17 00:00:00 2001 From: theraven Date: Fri, 16 Jul 2010 11:49:51 +0000 Subject: [PATCH] Don't leak memory when throwing exceptions. --- eh_personality.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eh_personality.c b/eh_personality.c index 0b41b63..3362951 100644 --- a/eh_personality.c +++ b/eh_personality.c @@ -36,6 +36,11 @@ struct objc_exception id object; }; +static void cleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *e) +{ + free((struct objc_exception*) ((char*)e - offsetof(struct objc_exception, + unwindHeader))); +} /** * */ @@ -44,6 +49,7 @@ void objc_exception_throw(id object) struct objc_exception *ex = calloc(1, sizeof(struct objc_exception)); ex->unwindHeader.exception_class = objc_exception_class; + ex->unwindHeader.exception_cleanup = cleanup; ex->object = object; @@ -231,6 +237,7 @@ _Unwind_Reason_Code __gnu_objc_personality_v0(int version, action.landing_pad = ex->landingPad; selector = ex->handlerSwitchValue; object = ex->object; + free(ex); } _Unwind_SetIP(context, (unsigned long)action.landing_pad);