env can be ignored for now - this is just a wrapper for ZenFS class.
Here, we basically do the following.
Create a new file via NewWritableFile() - the result is put into file local variable (std::unique_ptr)
We close the file explicitly via Close() method
We delete the closed file explicitly via DeleteFile() method - this in turns removes corresponding zone file from the files_ map and calls delete zoneFile
At the end of scope std::unique_ptr's destructor is called causing a call to ZonedWritableFile's destructor which in turn calls zoneFile_->CloseWR() on an already deleted (freed) zone.
The problem can definitely be fixed from the library user side - by calling DeleteFile() when file (std::unique_ptr) is out of scope.
rocksdb.use_direct_io_for_flush_and_compaction
MTR test case run under ASan/Valgrind helped to reveal the followingheap-use-after-free
problem.This problem can be narrowed down to the following code fragment
env
can be ignored for now - this is just a wrapper forZenFS
class. Here, we basically do the following.NewWritableFile()
- the result is put intofile
local variable (std::unique_ptr
)Close()
methodDeleteFile()
method - this in turns removes corresponding zone file from thefiles_
map and callsdelete zoneFile
std::unique_ptr
's destructor is called causing a call toZonedWritableFile
's destructor which in turn callszoneFile_->CloseWR()
on an already deleted (freed) zone.The problem can definitely be fixed from the library user side - by calling
DeleteFile()
whenfile
(std::unique_ptr
) is out of scope.However, the question is should the library itself take care of such scenario?