Delete TFile doesn't work. SysError in <TFile::TFile>: file ~~.root can not be opened for reading (Too many open files)

This isn’t true. It never crashes here.

I did for a while check file==NULL (earlier than c++11), and also file->IsZombie() seperately, if file is a null pointer, or points at null, calling IsZombie() actually causes segment and crashes.

I did have a combination of nullptr/Null or IsZombie(), and if by any reason IsZombie() is called, segment fault.

This isn’t true. It never crashes here.

Well … the behavior of calling a function on a nullptr is “unspecified” behavior and might indeed sometime not crash. What do you expect the behavior to be?

if file is a null pointer, or points at null, calling IsZombie() actually causes segment and crashes.

Yes, that’s why you need to have the 2 test inside the same if statement to benefit from the ‘boolean’ optimized that says that the 2nd part of a OR (||) is not evaluated if the 1st is true. Or you can write it as:

if (file == nullptr) {
    return;
} else if (file->IsZombie()) {
    delete file;
    return;
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.