Fixed memory leak in case of stopSync : delete Sync messages remaining in the queue before.
authorEdouard Tisserant <edouard@pep-project.org>
Fri, 19 May 2017 10:35:35 +0200
changeset 19401e62c252585
parent 193 0d26e0a12324
child 195 cbfe333e6df2
Fixed memory leak in case of stopSync : delete Sync messages remaining in the queue before.
pEpObjCAdapter/PEPObjCAdapter.m
pEpObjCAdapter/PEPQueue.h
pEpObjCAdapter/PEPQueue.m
     1.1 --- a/pEpObjCAdapter/PEPObjCAdapter.m	Thu May 18 16:13:51 2017 +0200
     1.2 +++ b/pEpObjCAdapter/PEPObjCAdapter.m	Fri May 19 10:35:35 2017 +0200
     1.3 @@ -385,9 +385,10 @@
     1.4      
     1.5      if (syncQueue)
     1.6      {
     1.7 -        // FIXME : memory leak ! unallocate sync message waiting in the queue
     1.8 -        
     1.9 -        [syncQueue kill];
    1.10 +        [syncQueue purge:^(id item){
    1.11 +            sync_msg_t *msg = [item pointerValue];
    1.12 +            free_sync_msg(msg);
    1.13 +        }];
    1.14          
    1.15          [syncThreadJoinCond lockWhenCondition:YES];
    1.16          [syncThreadJoinCond unlock];
     2.1 --- a/pEpObjCAdapter/PEPQueue.h	Thu May 18 16:13:51 2017 +0200
     2.2 +++ b/pEpObjCAdapter/PEPQueue.h	Fri May 19 10:35:35 2017 +0200
     2.3 @@ -8,6 +8,8 @@
     2.4  
     2.5  #import <Foundation/Foundation.h>
     2.6  
     2.7 +typedef void (^deleteOp)(id);
     2.8 +
     2.9  @interface PEPQueue : NSObject
    2.10  
    2.11  - (void)enqueue:(id)object;
    2.12 @@ -18,6 +20,8 @@
    2.13  
    2.14  - (void)kill;
    2.15  
    2.16 +- (void)purge:(deleteOp)del;
    2.17 +
    2.18  - (NSUInteger)count;
    2.19  
    2.20  @end
     3.1 --- a/pEpObjCAdapter/PEPQueue.m	Thu May 18 16:13:51 2017 +0200
     3.2 +++ b/pEpObjCAdapter/PEPQueue.m	Fri May 19 10:35:35 2017 +0200
     3.3 @@ -100,14 +100,34 @@
     3.4  
     3.5  - (void)kill
     3.6  {
     3.7 -    _queue = nil;
     3.8 +    @synchronized(self) {
     3.9 +        _queue = nil;
    3.10 +    }
    3.11 +    
    3.12 +    [_cond signal];
    3.13 +}
    3.14 +
    3.15 +- (void)purge:(deleteOp)del
    3.16 +{
    3.17 +    @synchronized(self) {
    3.18 +        id item;
    3.19 +        for (item in _queue)
    3.20 +        {
    3.21 +            del(item);
    3.22 +        }
    3.23 +        _queue = nil;
    3.24 +    }
    3.25      
    3.26      [_cond signal];
    3.27  }
    3.28  
    3.29  - (NSUInteger)count
    3.30  {
    3.31 -    return [_queue count];
    3.32 +    NSUInteger res;
    3.33 +    @synchronized(self) {
    3.34 +        res = [_queue count];
    3.35 +    }
    3.36 +    return res;
    3.37  }
    3.38  
    3.39  - (void)dealloc