[vtkusers] Memory Leaks in Cocoa implementation

Antoine Rosset rossetantoine at bluewin.ch
Mon Dec 8 15:21:59 EST 2008


Hi,

There are 2 memory leaks in the SetCocoaManager functions  
(vtkCocoaRenderWindowInteractor.mm and vtkCocoaRenderWindow.mm)

if manager is equal to NULL, the function doesn't release this- 
 >CocoaManager, but do nothing, since manager is equal to NULL.

I modified this line

NSMutableDictionary* cocoaManager =
       reinterpret_cast<NSMutableDictionary *>(manager);

in

NSMutableDictionary* cocoaManager =
       reinterpret_cast<NSMutableDictionary *>(this->CocoaManager);


Here is the corrected version:

void vtkCocoaRenderWindowInteractor::SetCocoaManager(void *manager)
{
   if (manager == NULL)
     {
     NSMutableDictionary* cocoaManager =
       reinterpret_cast<NSMutableDictionary *>(this->CocoaManager);
     #ifdef __OBJC_GC__
       [[NSGarbageCollector defaultCollector]  
enableCollectorForPointer:cocoaManager];
     #else
       [cocoaManager release];
     #endif
     }
   else
     {
     NSMutableDictionary* cocoaManager =
       reinterpret_cast<NSMutableDictionary *>(manager);
     #ifdef __OBJC_GC__
       [[NSGarbageCollector defaultCollector]  
disableCollectorForPointer:cocoaManager];
     #else
       [cocoaManager retain];
     #endif
     }
   this->CocoaManager = manager;
}


void vtkCocoaRenderWindow::SetCocoaManager(void *manager)
{
   if (manager == NULL)
     {
     NSMutableDictionary* cocoaManager =
       reinterpret_cast<NSMutableDictionary *>(this->CocoaManager);
     #ifdef __OBJC_GC__
       [[NSGarbageCollector defaultCollector]
         enableCollectorForPointer:cocoaManager];
     #else
       [cocoaManager release];
     #endif
     }
   else
     {
     NSMutableDictionary* cocoaManager =
       reinterpret_cast<NSMutableDictionary *>(manager);
     #ifdef __OBJC_GC__
       [[NSGarbageCollector defaultCollector]
         disableCollectorForPointer:cocoaManager];
     #else
       [cocoaManager retain];
     #endif
     }
   this->CocoaManager = manager;
}


Antoine Rosset

<> Antoine Rosset, M.D.
<> OsiriX Foundation, VP
<> OsiriX DICOM Viewer: http://www.osirix-viewer.com
<> LaTour Hospital & Geneva University Hospital - Radiology
<> Phone: + 41 78 7243037
<> 20 Micheli-Du-Crest, CH-1205 Geneva
<> Switzerland, Europe









-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081208/90e6dbfe/attachment.htm>


More information about the vtkusers mailing list