Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#49 Bug in read_reading, mfclose() not working

closed-fixed
None
5
2005-09-19
2005-09-12
Ken
No

Hi,
I am using io_lib to develop an application.
I might be wrong. But the line 97 in

Read *read_reading(char *fn, int format) {

97: mfclose(fp);

is not actually working. Here fp->fp is in my case a
NULL pointer, resulting from the mfcreate(udata, usize)
in the function freopen_compressed(...) in compress.c
The consequence of this is that mfclose() has never
closed those opened fp, and the system would stopping
fopen new files when there are too many opened files.

I fixed this problem by adding a line: mfclose(fp);

FILE *freopen_compressed(mFILE *fp, mFILE **ofp)
{
...
mfclose(fp); //fclose compressed files
return mfcreate(udata, usize);
}

Let me know if this makes sense. Thanks!

-Ken <kchen@watson.wustl.edu>

Discussion

  • James Bonfield
    James Bonfield
    2005-09-19

    • assigned_to: nobody --> jkbonfield
    • status: open --> closed-fixed
     
  • James Bonfield
    James Bonfield
    2005-09-19

    Logged In: YES
    user_id=154581

    I see the leak now. Thanks for reporting this. I think your
    fix is correct and I've checked it into CVS.

    I do not understand why the mfclose in read_reading failed
    though. mfclose has a "if (mf->fp) fclose(mf->fp)" check
    (although I can't say when that was added) so it's valid to
    pass in mFILEs that were created via mfcreate.

    Maybe it's an issue caused through leaking file descriptors
    though that caused the bug to manifest itself elsewhere. It
    seems that I need a better tool for checking those as
    valgrind didn't spot it.

    James