Skip to content

Commit

Permalink
EER: repair file handle leak reported in GitHub issue #819 by @KiSchnell
Browse files Browse the repository at this point in the history


and @mokca.
  • Loading branch information
biochem-fan committed Feb 24, 2022
1 parent cf55fbf commit 505e422
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/renderEER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ void EERRenderer::read(FileName _fn_movie, int eer_upsampling)

silenceTIFFWarnings();

// Try reading as TIFF; this handle is kept open
ftiff = TIFFOpen(fn_movie.c_str(), "r");
// Try reading as TIFF
TIFF *ftiff = TIFFOpen(fn_movie.c_str(), "r");

if (ftiff == NULL)
{
Expand Down Expand Up @@ -171,7 +171,7 @@ void EERRenderer::read(FileName _fn_movie, int eer_upsampling)

// Find the number of frames
nframes = TIFFNumberOfDirectories(ftiff);

TIFFClose(ftiff);
#ifdef DEBUG_EER
printf("EER in TIFF: %s nframes = %d\n", fn_movie.c_str(), nframes);
#endif
Expand All @@ -188,7 +188,8 @@ void EERRenderer::readLegacy(FILE *fh)
buf = (unsigned char*)malloc(file_size);
if (buf == NULL)
REPORT_ERROR("Failed to allocate the buffer.");
fread(buf, sizeof(char), file_size, fh);
if (fread(buf, sizeof(char), file_size, fh) != file_size)
REPORT_ERROR("EERRenderer::readLegacy: Failed to read the expected size from " + fn_movie);
RCTOC(TIMING_READ_EER);

/* Build frame index */
Expand Down Expand Up @@ -227,6 +228,8 @@ void EERRenderer::lazyReadFrames()
{
if (!read_data) // cannot return from within omp critical
{
TIFF *ftiff = TIFFOpen(fn_movie.c_str(), "r");

frame_starts.resize(nframes, 0);
frame_sizes.resize(nframes, 0);
buf = (unsigned char*)malloc(file_size); // This is big enough
Expand Down
1 change: 0 additions & 1 deletion src/renderEER.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class EERRenderer {
private:

FileName fn_movie;
TIFF *ftiff;

bool ready;
bool is_legacy;
Expand Down

0 comments on commit 505e422

Please sign in to comment.