mirror of https://github.com/mgba-emu/mgba.git
Qt: Flesh out VFileDevice more, to avoid leak
This commit is contained in:
parent
5b8d64b0b5
commit
80fb86a930
|
@ -91,6 +91,10 @@ VFileDevice::VFileDevice(const QString& filename, QIODevice::OpenMode mode, QObj
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VFileDevice::~VFileDevice() {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
void VFileDevice::close() {
|
void VFileDevice::close() {
|
||||||
if (!m_vf) {
|
if (!m_vf) {
|
||||||
return;
|
return;
|
||||||
|
@ -117,6 +121,13 @@ VFileDevice& VFileDevice::operator=(VFile* vf) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VFile* VFileDevice::take() {
|
||||||
|
VFile* vf = m_vf;
|
||||||
|
m_vf = nullptr;
|
||||||
|
QIODevice::close();
|
||||||
|
return vf;
|
||||||
|
}
|
||||||
|
|
||||||
qint64 VFileDevice::readData(char* data, qint64 maxSize) {
|
qint64 VFileDevice::readData(char* data, qint64 maxSize) {
|
||||||
return m_vf->read(m_vf, data, maxSize);
|
return m_vf->read(m_vf, data, maxSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ Q_OBJECT
|
||||||
public:
|
public:
|
||||||
VFileDevice(VFile* vf = nullptr, QObject* parent = nullptr);
|
VFileDevice(VFile* vf = nullptr, QObject* parent = nullptr);
|
||||||
VFileDevice(const QString&, QIODevice::OpenMode, QObject* parent = nullptr);
|
VFileDevice(const QString&, QIODevice::OpenMode, QObject* parent = nullptr);
|
||||||
|
virtual ~VFileDevice();
|
||||||
|
|
||||||
virtual void close() override;
|
virtual void close() override;
|
||||||
virtual bool seek(qint64 pos) override;
|
virtual bool seek(qint64 pos) override;
|
||||||
|
@ -29,6 +30,7 @@ public:
|
||||||
|
|
||||||
VFileDevice& operator=(VFile*);
|
VFileDevice& operator=(VFile*);
|
||||||
operator VFile*() { return m_vf; }
|
operator VFile*() { return m_vf; }
|
||||||
|
VFile* take();
|
||||||
|
|
||||||
static VFile* wrap(QIODevice*, QIODevice::OpenMode);
|
static VFile* wrap(QIODevice*, QIODevice::OpenMode);
|
||||||
static VFile* wrap(QFileDevice*, QIODevice::OpenMode);
|
static VFile* wrap(QFileDevice*, QIODevice::OpenMode);
|
||||||
|
|
Loading…
Reference in New Issue