mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 00:24:43 +02:00
Fix memory leak in [RecentsDataSource dataSource:didStateChange:]
The block passed into `[MXSession listenToEventsOfTypes:onEvent:]` is stored with a strong reference in the `listenerBlock` property of `MXSessionEventListener`. The method also returns the listener and it is then stored into the `roomTagsListenerByUserId` dictionary on `self`. Since a strong reference to `self` is captured in the block that means the block retains `self` (via the capture) and `self` retains the block (via `roomTagsListenerByUserId`) so there is a memory leak. The bug is most easily reproduced during testing #4168 which involves closing the current and creating a new session. Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
This commit is contained in:
@@ -337,9 +337,12 @@ NSString *const kRecentsDataSourceTapOnDirectoryServerChange = @"kRecentsDataSou
|
||||
if ((aState == MXKDataSourceStateReady) && dataSource.mxSession.myUser.userId)
|
||||
{
|
||||
// Register the room tags updates to refresh the favorites order
|
||||
MXWeakify(self);
|
||||
id roomTagsListener = [dataSource.mxSession listenToEventsOfTypes:@[kMXEventTypeStringRoomTag]
|
||||
onEvent:^(MXEvent *event, MXTimelineDirection direction, id customObject) {
|
||||
|
||||
MXStrongifyAndReturnIfNil(self);
|
||||
|
||||
// Consider only live event
|
||||
if (direction == MXTimelineDirectionForwards)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user