[Issue 14868] MmFile destructor seems to corrupt memory

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 6 08:20:44 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14868

--- Comment #5 from Sergei Degtiarev <sdegtiarev at yahoo.com> ---
MmFile class destructor makes only two system calls:
~this()
{
  unmap();
  errnoEnforce(fd == -1 || fd <= 2 || .close(fd) != -1, 
    "Could not close handle");
}
and the second one, .close(fd), fails with EBADF errno, obviously the file
descriptor is already closed. Somehow GC converts descriptive error message
into general InvalidMemoryOperationError.
What I found, if the File is created as independent instance, it is always
deleted first, so the file descriptor is closed once in File destructor and
after that is tried to be closed in MmFile destructor resulting to an
exception.
  I would recommend (at least as temporary fix for POSIX) to exclude .close()
result check, the only meaningful error returned is due to close() duplicate
call, which is harmless.
  Also a question, how it happens that File destructor is always called before
MmFile one? I tried all possible combinations to create them with same result.

--


More information about the Digitalmars-d-bugs mailing list