Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix memory leaks when saving scene fails #355

Closed
wants to merge 1 commit into from
Closed

BUG: Fix memory leaks when saving scene fails #355

wants to merge 1 commit into from

Conversation

msmolens
Copy link
Member

This commit replaces manual memory management with smart pointers to fix memory
leaks in vtkITKImageWriter::Write() when an exception occurs while writing the
image.

Fixes issue #3717:

To reproduce:
 -> Create folder ~/test
 -> Start Slicer
 -> Download MRHead
 -> File -> Save Scene
 -> Click "Change directory for selected files" and select "~/test"
 -> after selecting the folder and before clicking Save => chmod -w ~/test
 -> Click Save
 -> When you get the "Cannot write data file" error, click Yes to say you want to continue despite the problem
 -> When you get the "Cannot write scene file" error, click Yes to say you ignore these errors and close saving
 -> Close Slicer (click Exit and discard modification)

Then, you get the following leaks:

Class "vtkCellData" has 1 instance still around.
Class "vtkInformationIntegerVectorValue" has 3 instances still around.
Class "vtkInformationVector" has 15 instances still around.
Class "vtkPointData" has 1 instance still around.
Class "vtkImageFlip" has 1 instance still around.
Class "vtkTrivialProducer" has 1 instance still around.
Class "vtkMatrix4x4" has 1 instance still around.
Class "vtkPoints" has 1 instance still around.
Class "vtkInformation" has 21 instances still around.
Class "vtkMultiThreader" has 1 instance still around.
Class "vtkInformationIntegerPointerValue" has 2 instances still around.
Class "vtkIdList" has 1 instance still around.
Class "vtkImageExport" has 1 instance still around.
Class "vtkDoubleArray" has 1 instance still around.
Class "vtkAlgorithmOutput" has 1 instance still around.
Class "vtkImageStencilData" has 1 instance still around.
Class "vtkInformationIntegerValue" has 26 instances still around.
Class "vtkExtentTranslator" has 1 instance still around.
Class "vtkImageData" has 1 instance still around.
Class "vtkInformationStringValue" has 1 instance still around.
Class "vtkInformationExecutivePortVectorValue" has 1 instance still around.
Class "vtkShortArray" has 1 instance still around.
Class "vtkVoxel" has 1 instance still around.
Class "vtkFieldData" has 2 instances still around.
Class "vtkInformationDoubleVectorValue" has 2 instances still around.
Class "vtkStreamingDemandDrivenPipeline" has 3 instances still around.
Class "vtkInformationExecutivePortValue" has 4 instances still around.

This commit replaces manual memory management with smart pointers to fix memory
leaks in vtkITKImageWriter::Write() when an exception occurs while writing the
image.

Fixes issue #3717:

    To reproduce:
     -> Create folder ~/test
     -> Start Slicer
     -> Download MRHead
     -> File -> Save Scene
     -> Click "Change directory for selected files" and select "~/test"
     -> after selecting the folder and before clicking Save => chmod -w ~/test
     -> Click Save
     -> When you get the "Cannot write data file" error, click Yes to say you want to continue despite the problem
     -> When you get the "Cannot write scene file" error, click Yes to say you ignore these errors and close saving
     -> Close Slicer (click Exit and discard modification)

    Then, you get the following leaks:

    Class "vtkCellData" has 1 instance still around.
    Class "vtkInformationIntegerVectorValue" has 3 instances still around.
    Class "vtkInformationVector" has 15 instances still around.
    Class "vtkPointData" has 1 instance still around.
    Class "vtkImageFlip" has 1 instance still around.
    Class "vtkTrivialProducer" has 1 instance still around.
    Class "vtkMatrix4x4" has 1 instance still around.
    Class "vtkPoints" has 1 instance still around.
    Class "vtkInformation" has 21 instances still around.
    Class "vtkMultiThreader" has 1 instance still around.
    Class "vtkInformationIntegerPointerValue" has 2 instances still around.
    Class "vtkIdList" has 1 instance still around.
    Class "vtkImageExport" has 1 instance still around.
    Class "vtkDoubleArray" has 1 instance still around.
    Class "vtkAlgorithmOutput" has 1 instance still around.
    Class "vtkImageStencilData" has 1 instance still around.
    Class "vtkInformationIntegerValue" has 26 instances still around.
    Class "vtkExtentTranslator" has 1 instance still around.
    Class "vtkImageData" has 1 instance still around.
    Class "vtkInformationStringValue" has 1 instance still around.
    Class "vtkInformationExecutivePortVectorValue" has 1 instance still around.
    Class "vtkShortArray" has 1 instance still around.
    Class "vtkVoxel" has 1 instance still around.
    Class "vtkFieldData" has 2 instances still around.
    Class "vtkInformationDoubleVectorValue" has 2 instances still around.
    Class "vtkStreamingDemandDrivenPipeline" has 3 instances still around.
    Class "vtkInformationExecutivePortValue" has 4 instances still around.
@msmolens msmolens added the bug label Sep 25, 2015
@jcfr
Copy link
Member

jcfr commented Sep 25, 2015

👍 LGTM

@msmolens
Copy link
Member Author

Integrated in 24578

@msmolens msmolens closed this Sep 25, 2015
@msmolens msmolens deleted the fix-issue-3717-save-scene-memory-leak branch September 25, 2015 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants