areaDetector / ADCore

The home of the core components of the EPICS areaDetector software. It includes base classes for drivers and code for all of the standard plugins.
https://areadetector.github.io/master/index.html
Other
20 stars 65 forks source link

Fix possible memory leak when using NDFileModeCapture in NDPluginFile #490

Closed flowln closed 9 months ago

flowln commented 1 year ago

Previously, when using the Capture mode, if you started a new capture without saving the previously captured frames to a file, the pCapture array holding the frames wouldn't be free'd properly, causing a memory leak. Another way of causing such leak was by changing the capture mode to stream without saving the frames to a file.

With this commit, when resetting NDFileNumCaptured before starting a new capture, we make sure to also empty the capture buffer if it is not empty yet, so that no buffer is leaked.

I used Valgrind to try to make sure there'd be no other way of reaching those NDArrays held in pCapture after overriding it or setting NDFileModeCapture to zero, but sorry if I missed something! :slightly_smiling_face:

MarkRivers commented 9 months ago

I had made similar fixes to this PR but with some cleanup and additional features. These were done in these commits:

86e30c22232fe9a09179473aa7f96cc4cd94bef8

78781ddeacd8700b428950d5a815d230c619aa71

48e14a63b662d6c2c1b2cd3e860bbadd30342e08

bb49af432db3a70963df3bd7adcca7786e3bf62d