Check that QIODevice::open() is successful, and explicitly call close()
This commit is contained in:
@@ -340,11 +340,11 @@ bool CommandlineOptions::contains_play_options() const {
|
||||
QByteArray CommandlineOptions::Serialize() const {
|
||||
|
||||
QBuffer buf;
|
||||
buf.open(QIODevice::WriteOnly);
|
||||
|
||||
QDataStream s(&buf);
|
||||
s << *this;
|
||||
buf.close();
|
||||
if (buf.open(QIODevice::WriteOnly)) {
|
||||
QDataStream s(&buf);
|
||||
s << *this;
|
||||
buf.close();
|
||||
}
|
||||
|
||||
return buf.data().toBase64();
|
||||
|
||||
@@ -354,10 +354,10 @@ void CommandlineOptions::Load(const QByteArray &serialized) {
|
||||
|
||||
QByteArray copy = QByteArray::fromBase64(serialized);
|
||||
QBuffer buf(©);
|
||||
buf.open(QIODevice::ReadOnly);
|
||||
|
||||
QDataStream s(&buf);
|
||||
s >> *this;
|
||||
if (buf.open(QIODevice::ReadOnly)) {
|
||||
QDataStream s(&buf);
|
||||
s >> *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -387,9 +387,12 @@ void Database::ExecSchemaCommandsFromFile(QSqlDatabase &db, const QString &filen
|
||||
|
||||
// Open and read the database schema
|
||||
QFile schema_file(filename);
|
||||
if (!schema_file.open(QIODevice::ReadOnly))
|
||||
if (!schema_file.open(QIODevice::ReadOnly)) {
|
||||
qFatal("Couldn't open schema file %s", filename.toUtf8().constData());
|
||||
return;
|
||||
}
|
||||
ExecSchemaCommands(db, QString::fromUtf8(schema_file.readAll()), schema_version, in_transaction);
|
||||
schema_file.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -358,10 +358,13 @@ void SongLoader::EffectiveSongLoad(Song *song) {
|
||||
}
|
||||
|
||||
void SongLoader::LoadPlaylist(ParserBase *parser, const QString &filename) {
|
||||
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
songs_ = parser->Load(&file, filename, QFileInfo(filename).path());
|
||||
file.close();
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
songs_ = parser->Load(&file, filename, QFileInfo(filename).path());
|
||||
file.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static bool CompareSongs(const Song &left, const Song &right) {
|
||||
@@ -429,9 +432,10 @@ void SongLoader::StopTypefind() {
|
||||
|
||||
// Parse the playlist
|
||||
QBuffer buf(&buffer_);
|
||||
buf.open(QIODevice::ReadOnly);
|
||||
songs_ = parser_->Load(&buf);
|
||||
buf.close();
|
||||
if (buf.open(QIODevice::ReadOnly)) {
|
||||
songs_ = parser_->Load(&buf);
|
||||
buf.close();
|
||||
}
|
||||
|
||||
}
|
||||
else if (success_) {
|
||||
|
||||
Reference in New Issue
Block a user