Pr/fix unit tests memory leaks (#1795)

* Fix some concurrency problems detected by Xcode 8's new Thread Sanitizer.

Some of these changes are arguably just to silence the warnings from Thread Sanitizer.

* Fix several memory leaks in the unit tests.

A number of the unit test source files are compield with `-fno-objc-arc`.  This was clearly overlooked when writing several of the unit tests.

Fixed by (mostly) switching to use of `-autorelease` for the problem code.

NOTE: This commit doesn't fix all the memory leaks found.  There's still at least one leak in `-[ASDisplayNodeTests testSetNeedsDataFetchImmediateState]`, and several leaks in `ASBasicImageDownloader.mm`.  I wasn't able to find a trivial cause to these, unfortunately.
This commit is contained in:
John Engelhart
2016-06-22 16:56:53 -07:00
committed by appleguy
parent a05d3119ad
commit ea64d7d09b
6 changed files with 98 additions and 95 deletions

View File

@@ -442,7 +442,7 @@ typedef enum {
-(BOOL)_tryRetain { \
__typeof__(_rc_ivar) _prev; \
do { \
_prev = _rc_ivar; \
_prev = __atomic_load_n(&_rc_ivar, __ATOMIC_SEQ_CST);; \
if (_prev & 1) { \
return 0; \
} else if (_prev == -2) { \
@@ -454,12 +454,13 @@ typedef enum {
return 1; \
} \
-(BOOL)_isDeallocating { \
if (_rc_ivar == -2) { \
__typeof__(_rc_ivar) _prev = __atomic_load_n(&_rc_ivar, __ATOMIC_SEQ_CST); \
if (_prev == -2) { \
return 1; \
} else if (_rc_ivar < -2) { \
} else if (_prev < -2) { \
__builtin_trap(); /* BUG: over-release elsewhere */ \
} \
return _rc_ivar & 1; \
return _prev & 1; \
}
#define _OBJC_SUPPORTED_INLINE_REFCNT_LOGIC(_rc_ivar, _dealloc2main) \