Check that QIODevice::open() is successful, and explicitly call close()
This commit is contained in:
@@ -63,15 +63,15 @@ SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
|
||||
QBuffer buffer(&data);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
|
||||
SongList ret;
|
||||
if (!buffer.open(QIODevice::ReadOnly)) return SongList();
|
||||
|
||||
QXmlStreamReader reader(&buffer);
|
||||
if (!Utilities::ParseUntilElementCI(&reader, "asx")) {
|
||||
return ret;
|
||||
buffer.close();
|
||||
return SongList();
|
||||
}
|
||||
|
||||
SongList ret;
|
||||
while (!reader.atEnd() && Utilities::ParseUntilElementCI(&reader, "entry")) {
|
||||
Song song = ParseTrack(&reader, dir, collection_search);
|
||||
if (song.is_valid()) {
|
||||
@@ -79,6 +79,8 @@ SongList ASXParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
}
|
||||
}
|
||||
|
||||
buffer.close();
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
@@ -46,8 +46,6 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
|
||||
Q_UNUSED(playlist_path);
|
||||
|
||||
SongList ret;
|
||||
|
||||
M3UType type = STANDARD;
|
||||
Metadata current_metadata;
|
||||
|
||||
@@ -56,7 +54,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
data.replace("\n\n", "\n");
|
||||
QByteArray bytes = data.toUtf8();
|
||||
QBuffer buffer(&bytes);
|
||||
buffer.open(QIODevice::ReadOnly);
|
||||
if (!buffer.open(QIODevice::ReadOnly)) return SongList();
|
||||
|
||||
QString line = QString::fromUtf8(buffer.readLine()).trimmed();
|
||||
if (line.startsWith("#EXTM3U")) {
|
||||
@@ -65,6 +63,7 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
line = QString::fromUtf8(buffer.readLine()).trimmed();
|
||||
}
|
||||
|
||||
SongList ret;
|
||||
forever {
|
||||
if (line.startsWith('#')) {
|
||||
// Extended info or comment.
|
||||
@@ -95,6 +94,8 @@ SongList M3UParser::Load(QIODevice *device, const QString &playlist_path, const
|
||||
line = QString::fromUtf8(buffer.readLine()).trimmed();
|
||||
}
|
||||
|
||||
buffer.close();
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
@@ -166,9 +166,12 @@ SongList PlaylistParser::LoadFromFile(const QString &filename) const {
|
||||
|
||||
// Open the file
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
if (!file.open(QIODevice::ReadOnly)) return SongList();
|
||||
|
||||
return parser->Load(&file, filename, info.absolutePath());
|
||||
SongList ret = parser->Load(&file, filename, info.absolutePath());
|
||||
file.close();
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user