Commit b327848
committed
record/avfoundation: plug MRC leaks of AVAssetWriter objects and GCD queue
record_avfoundation_t holds five Objective-C object pointers as plain
C struct members:
AVAssetWriter *assetWriter;
AVAssetWriterInput *videoInput;
AVAssetWriterInput *audioInput;
AVAssetWriterInputPixelBufferAdaptor *pixelBufferAdaptor;
dispatch_queue_t encodingQueue;
All five are populated via alloc+init (or dispatch_queue_create), each
of which hands back a +1-retained object.
avfoundation_release_handle() cleared these fields with plain
handle->assetWriter = nil;
Under ARC that is fine because modern clang auto-qualifies ObjC struct
members as __strong and the assignment releases the prior value.
Under MRC the assignment is a bare pointer overwrite - the previously-
retained object is never released. RetroArch builds .m files without
-fobjc-arc in the top-level qb Makefile and in the
RetroArch/_Metal/_OSX107/_iOS13 Xcode projects (only _iOS6/8/9/10/11/
_iOS11_Metal and the Theos iOS build enable ARC globally), so every
record_stop / error-path teardown leaked four AVAssetWriter* objects
and one GCD queue.
Fix with two small helper macros gated on __has_feature(objc_arc):
* RA_RELEASE_OBJ(field) -- [field release]; field = nil; (MRC)
field = nil; (ARC)
* RA_RELEASE_DQ(field) -- dispatch_release + nil on MRC
(with a NULL guard since
dispatch_release(NULL) is undefined;
[nil release] is a safe no-op so the
OBJ variant does not need one).
Under ARC both macros expand to the same field-assignment-to-nil the
code already used, so there is no semantic change on that build path.
Under MRC the retain-count arithmetic is now correct.
Also fixes the same leak on the 'canAddInput audio input' error path
in avfoundation_record_init, where the freshly-allocated
handle->audioInput was being dropped with = nil (the alloc+init from
a handful of lines earlier leaked under MRC, then the assetWriter was
used to record video-only).
Thread-safety: unchanged. The release helper is only invoked from
record_free / init error paths on the main thread after the encoding
queue has drained; no concurrent readers of the ivars.
Build matrix impact: this fixes the leak everywhere the file is
compiled as MRC (top-level Makefile macOS builds and the
RetroArch/_Metal/_OSX107/_iOS13 Xcode projects). The ARC builds
(_iOS6/8/9/10/11/_iOS11_Metal + Theos) are unaffected because the ARC
expansion is identical to the old code.1 parent ebf6708 commit b327848
1 file changed
Lines changed: 36 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
36 | 66 | | |
37 | 67 | | |
38 | 68 | | |
| |||
140 | 170 | | |
141 | 171 | | |
142 | 172 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
148 | 178 | | |
149 | 179 | | |
150 | 180 | | |
| |||
343 | 373 | | |
344 | 374 | | |
345 | 375 | | |
346 | | - | |
| 376 | + | |
347 | 377 | | |
348 | 378 | | |
349 | 379 | | |
| |||
0 commit comments