stream: fix buffered_sys and cached_file destruction
We had to introduce out-of-order construction for those classes, but we forgot to implement out-of-order destruction. File gets closed first by cached_file::m_source destructor, then inherited destructor cache::~cache() which flushes the cache is called. Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
2b1bfc235d
commit
73d03d81af
@ -858,6 +858,11 @@ namespace stdex
|
||||
m_source = &source;
|
||||
}
|
||||
|
||||
void done()
|
||||
{
|
||||
m_source = nullptr;
|
||||
}
|
||||
|
||||
public:
|
||||
converter(_Inout_ basic& source) :
|
||||
basic(source.state()),
|
||||
@ -1215,6 +1220,13 @@ namespace stdex
|
||||
m_write_buffer(write_buffer_size)
|
||||
{}
|
||||
|
||||
void done()
|
||||
{
|
||||
if (m_source)
|
||||
flush_write();
|
||||
converter::done();
|
||||
}
|
||||
|
||||
public:
|
||||
buffer(_Inout_ basic& source, _In_ size_t read_buffer_size = default_buffer_size, _In_ size_t write_buffer_size = default_buffer_size) :
|
||||
converter(source),
|
||||
@ -1651,6 +1663,17 @@ namespace stdex
|
||||
#endif
|
||||
}
|
||||
|
||||
void done()
|
||||
{
|
||||
if (m_source) {
|
||||
flush_cache();
|
||||
if (!ok()) _Unlikely_
|
||||
throw std::runtime_error("cache flush failed"); // Data loss occured
|
||||
m_source->seek(m_offset);
|
||||
m_source = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
cache(_Inout_ basic_file& source, _In_ size_t cache_size = default_cache_size) :
|
||||
basic(source.state()),
|
||||
@ -2135,6 +2158,11 @@ namespace stdex
|
||||
init(m_source);
|
||||
}
|
||||
|
||||
virtual ~buffered_sys()
|
||||
{
|
||||
done();
|
||||
}
|
||||
|
||||
protected:
|
||||
basic_sys m_source;
|
||||
};
|
||||
@ -2697,6 +2725,11 @@ namespace stdex
|
||||
init(m_source);
|
||||
}
|
||||
|
||||
virtual ~cached_file()
|
||||
{
|
||||
done();
|
||||
}
|
||||
|
||||
///
|
||||
/// Opens file
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user