1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-22 07:54:18 +01:00

Fix memory leaks (#6376)

This commit is contained in:
Jonas Kvinge 2019-08-02 17:24:26 +02:00 committed by John Maguire
parent ec2e8be4d6
commit 546078c317
6 changed files with 18 additions and 22 deletions

View File

@ -33,15 +33,14 @@ static const int kTaglibSuffixCacheBytes = 8 * 1024;
}
CloudStream::CloudStream(const QUrl& url, const QString& filename,
const long length, const QString& auth,
QNetworkAccessManager* network)
const long length, const QString& auth)
: url_(url),
filename_(filename),
encoded_filename_(filename_.toUtf8()),
length_(length),
auth_(auth),
cursor_(0),
network_(network),
network_(new QNetworkAccessManager),
cache_(length),
num_requests_(0) {}

View File

@ -18,21 +18,20 @@
#ifndef GOOGLEDRIVESTREAM_H
#define GOOGLEDRIVESTREAM_H
#include <QObject>
#include <QList>
#include <QNetworkAccessManager>
#include <QObject>
#include <QSslError>
#include <QUrl>
#include <google/sparsetable>
#include <taglib/tiostream.h>
class QNetworkAccessManager;
class CloudStream : public QObject, public TagLib::IOStream {
Q_OBJECT
public:
CloudStream(const QUrl& url, const QString& filename, const long length,
const QString& auth, QNetworkAccessManager* network);
const QString& auth);
// Taglib::IOStream
virtual TagLib::FileName name() const;
@ -73,7 +72,7 @@ class CloudStream : public QObject, public TagLib::IOStream {
const QString auth_;
int cursor_;
QNetworkAccessManager* network_;
std::unique_ptr<QNetworkAccessManager> network_;
google::sparsetable<char> cache_;
int num_requests_;

View File

@ -22,7 +22,6 @@
#include <QCoreApplication>
#include <QDateTime>
#include <QFileInfo>
#include <QNetworkAccessManager>
#include <QTextCodec>
#include <QUrl>
#include <QVector>
@ -77,12 +76,6 @@
#define NumberToASFAttribute(x) \
TagLib::ASF::Attribute(QStringToTaglibString(QString::number(x)))
class FileRefFactory {
public:
virtual ~FileRefFactory() {}
virtual TagLib::FileRef* GetFileRef(const QString& filename) = 0;
};
class TagLibFileRefFactory : public FileRefFactory {
public:
virtual TagLib::FileRef* GetFileRef(const QString& filename) {
@ -122,7 +115,6 @@ const char* kASF_OriginalYear_ID = "WM/OriginalReleaseYear";
TagReader::TagReader()
: factory_(new TagLibFileRefFactory),
network_(new QNetworkAccessManager),
kEmbeddedCover("(embedded)") {}
void TagReader::ReadFile(const QString& filename,
@ -1332,8 +1324,8 @@ bool TagReader::ReadCloudFile(const QUrl& download_url, const QString& title,
pb::tagreader::SongMetadata* song) const {
qLog(Debug) << "Loading tags from" << title;
std::unique_ptr<CloudStream> stream(new CloudStream(
download_url, title, size, authorisation_header, network_));
std::unique_ptr<CloudStream> stream(
new CloudStream(download_url, title, size, authorisation_header));
stream->Precache();
std::unique_ptr<TagLib::File> tag;
if (mime_type == "audio/mpeg" &&

View File

@ -21,11 +21,11 @@
#include <QByteArray>
#include <taglib/xiphcomment.h>
#include <memory>
#include "config.h"
#include "tagreadermessages.pb.h"
class QNetworkAccessManager;
class QString;
class QTextCodec;
class QUrl;
@ -40,7 +40,11 @@ class PopularimeterFrame;
}
}
class FileRefFactory;
class FileRefFactory {
public:
virtual ~FileRefFactory() {}
virtual TagLib::FileRef* GetFileRef(const QString& filename) = 0;
};
/**
* This class holds all useful methods to read and write tags from/to files.
@ -119,8 +123,7 @@ class TagReader {
static TagLib::ID3v2::PopularimeterFrame* GetPOPMFrameFromTag(
TagLib::ID3v2::Tag* tag);
FileRefFactory* factory_;
QNetworkAccessManager* network_;
std::unique_ptr<FileRefFactory> factory_;
const std::string kEmbeddedCover;
};

View File

@ -403,6 +403,8 @@ TagCompleter::TagCompleter(LibraryBackend* backend, Playlist::Column column,
future);
}
TagCompleter::~TagCompleter() { model()->deleteLater(); }
void TagCompleter::ModelReady(QFuture<TagCompletionModel*> future) {
TagCompletionModel* model = future.result();
setModel(model);

View File

@ -157,6 +157,7 @@ class TagCompleter : public QCompleter {
public:
TagCompleter(LibraryBackend* backend, Playlist::Column column,
QLineEdit* editor);
~TagCompleter();
private slots:
void ModelReady(QFuture<TagCompletionModel*> future);