Check that QIODevice::open() is successful, and explicitly call close()

This commit is contained in:
Jonas Kvinge
2021-07-14 20:52:57 +02:00
parent f64c1dd9e5
commit 2eab763d74
15 changed files with 74 additions and 49 deletions

View File

@@ -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;
}