From e3b069cedcae09eb19d28d34f6cee97c0c4943bc Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Mon, 4 Jan 2016 10:25:03 -0800 Subject: [PATCH] Use the old association policy to determine whether to release an object This commit has been augmented to address the comments in https://github.com/Microsoft/libobjc2/commit/df7f9061670cce994730d1720150adc --- associate.m | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/associate.m b/associate.m index 37b9c26..d3ab8a9 100644 --- a/associate.m +++ b/associate.m @@ -166,12 +166,17 @@ static void setReference(struct reference_list *list, lock = lock_for_pointer(r); lock_spinlock(lock); } - r->policy = policy; - id old = r->object; - r->object = obj; - if (OBJC_ASSOCIATION_ASSIGN != r->policy) + @try { - objc_release(old); + if (OBJC_ASSOCIATION_ASSIGN != r->policy) + { + objc_release(r->object); + } + } + @finally + { + r->policy = policy; + r->object = obj; } if (needLock) {