all repos — mgba @ 80fb86a930f9f97f339f69e0f960863850176b51

mGBA Game Boy Advance Emulator

Qt: Flesh out VFileDevice more, to avoid leak
Vicki Pfau vi@endrift.com
Sat, 30 Jan 2021 16:01:06 -0800
commit

80fb86a930f9f97f339f69e0f960863850176b51

parent

5b8d64b0b5e5b3aa1edac7a98be6cbf471869dd0

2 files changed, 13 insertions(+), 0 deletions(-)

jump to
M src/platform/qt/VFileDevice.cppsrc/platform/qt/VFileDevice.cpp

@@ -91,6 +91,10 @@ setOpenMode(mode);

} } +VFileDevice::~VFileDevice() { + close(); +} + void VFileDevice::close() { if (!m_vf) { return;

@@ -115,6 +119,13 @@ close();

m_vf = vf; setOpenMode(QIODevice::ReadWrite); return *this; +} + +VFile* VFileDevice::take() { + VFile* vf = m_vf; + m_vf = nullptr; + QIODevice::close(); + return vf; } qint64 VFileDevice::readData(char* data, qint64 maxSize) {
M src/platform/qt/VFileDevice.hsrc/platform/qt/VFileDevice.h

@@ -20,6 +20,7 @@

public: VFileDevice(VFile* vf = nullptr, QObject* parent = nullptr); VFileDevice(const QString&, QIODevice::OpenMode, QObject* parent = nullptr); + virtual ~VFileDevice(); virtual void close() override; virtual bool seek(qint64 pos) override;

@@ -29,6 +30,7 @@ bool resize(qint64 sz);

VFileDevice& operator=(VFile*); operator VFile*() { return m_vf; } + VFile* take(); static VFile* wrap(QIODevice*, QIODevice::OpenMode); static VFile* wrap(QFileDevice*, QIODevice::OpenMode);