Delete remaining network replies and local redirct server in destructor

This commit is contained in:
Jonas Kvinge
2020-05-12 21:28:42 +02:00
parent 4bfad9dad8
commit e35501ff0a
46 changed files with 424 additions and 30 deletions

View File

@@ -51,7 +51,7 @@ TidalFavoriteRequest::~TidalFavoriteRequest() {
while (!replies_.isEmpty()) {
QNetworkReply *reply = replies_.takeFirst();
disconnect(reply, 0, this, 0);
disconnect(reply, nullptr, this, nullptr);
reply->abort();
reply->deleteLater();
}
@@ -152,6 +152,7 @@ void TidalFavoriteRequest::AddFavoritesReply(QNetworkReply *reply, const Favorit
if (replies_.contains(reply)) {
replies_.removeAll(reply);
disconnect(reply, nullptr, this, nullptr);
reply->deleteLater();
}
else {
@@ -254,6 +255,7 @@ void TidalFavoriteRequest::RemoveFavoritesReply(QNetworkReply *reply, const Favo
if (replies_.contains(reply)) {
replies_.removeAll(reply);
disconnect(reply, nullptr, this, nullptr);
reply->deleteLater();
}
else {

View File

@@ -84,14 +84,14 @@ TidalRequest::~TidalRequest() {
while (!replies_.isEmpty()) {
QNetworkReply *reply = replies_.takeFirst();
disconnect(reply, 0, this, 0);
disconnect(reply, nullptr, this, nullptr);
if (reply->isRunning()) reply->abort();
reply->deleteLater();
}
while (!album_cover_replies_.isEmpty()) {
QNetworkReply *reply = album_cover_replies_.takeFirst();
disconnect(reply, 0, this, 0);
disconnect(reply, nullptr, this, nullptr);
if (reply->isRunning()) reply->abort();
reply->deleteLater();
}
@@ -330,6 +330,7 @@ void TidalRequest::ArtistsReplyReceived(QNetworkReply *reply, const int limit_re
if (!replies_.contains(reply)) return;
replies_.removeAll(reply);
disconnect(reply, nullptr, this, nullptr);
reply->deleteLater();
QByteArray data = GetReplyData(reply, (offset_requested == 0));
@@ -521,6 +522,7 @@ void TidalRequest::AlbumsReceived(QNetworkReply *reply, const QString &artist_id
if (!replies_.contains(reply)) return;
replies_.removeAll(reply);
disconnect(reply, nullptr, this, nullptr);
reply->deleteLater();
QByteArray data = GetReplyData(reply, auto_login);
@@ -787,6 +789,7 @@ void TidalRequest::SongsReceived(QNetworkReply *reply, const QString &artist_id,
if (!replies_.contains(reply)) return;
replies_.removeAll(reply);
disconnect(reply, nullptr, this, nullptr);
reply->deleteLater();
QByteArray data = GetReplyData(reply, auto_login);
@@ -1127,6 +1130,7 @@ void TidalRequest::AlbumCoverReceived(QNetworkReply *reply, const QString &album
if (album_cover_replies_.contains(reply)) {
album_cover_replies_.removeAll(reply);
disconnect(reply, nullptr, this, nullptr);
reply->deleteLater();
}
else {

View File

@@ -179,9 +179,16 @@ TidalService::TidalService(Application *app, QObject *parent)
TidalService::~TidalService() {
while (!replies_.isEmpty()) {
QNetworkReply *reply = replies_.takeFirst();
disconnect(reply, nullptr, this, nullptr);
reply->abort();
reply->deleteLater();
}
while (!stream_url_requests_.isEmpty()) {
TidalStreamURLRequest *stream_url_req = stream_url_requests_.takeFirst();
disconnect(stream_url_req, 0, this, 0);
disconnect(stream_url_req, nullptr, this, nullptr);
stream_url_req->deleteLater();
}
@@ -208,7 +215,7 @@ void TidalService::Exit() {
void TidalService::ExitReceived() {
QObject *obj = static_cast<QObject*>(sender());
disconnect(obj, 0, this, 0);
disconnect(obj, nullptr, this, nullptr);
qLog(Debug) << obj << "successfully exited.";
wait_for_exit_.removeAll(obj);
if (wait_for_exit_.isEmpty()) emit ExitFinished();
@@ -338,6 +345,7 @@ void TidalService::AuthorisationUrlReceived(const QUrl &url) {
login_errors_.clear();
QNetworkReply *reply = network_->post(request, query);
replies_ << reply;
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandleLoginSSLErrors(QList<QSslError>)));
connect(reply, &QNetworkReply::finished, [=] { AccessTokenRequestFinished(reply); });
@@ -360,6 +368,9 @@ void TidalService::HandleLoginSSLErrors(QList<QSslError> ssl_errors) {
void TidalService::AccessTokenRequestFinished(QNetworkReply *reply) {
if (!replies_.contains(reply)) return;
replies_.removeAll(reply);
disconnect(reply, nullptr, this, nullptr);
reply->deleteLater();
login_sent_ = false;
@@ -503,6 +514,7 @@ void TidalService::SendLogin(const QString &api_token, const QString &username,
QNetworkReply *reply = network_->post(req, query);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(HandleLoginSSLErrors(QList<QSslError>)));
connect(reply, &QNetworkReply::finished, [=] { HandleAuthReply(reply); });
replies_ << reply;
//qLog(Debug) << "Tidal: Sending request" << url << query;
@@ -510,6 +522,9 @@ void TidalService::SendLogin(const QString &api_token, const QString &username,
void TidalService::HandleAuthReply(QNetworkReply *reply) {
if (!replies_.contains(reply)) return;
replies_.removeAll(reply);
disconnect(reply, nullptr, this, nullptr);
reply->deleteLater();
login_sent_ = false;
@@ -657,8 +672,8 @@ void TidalService::TryLogin() {
void TidalService::ResetArtistsRequest() {
if (artists_request_.get()) {
disconnect(artists_request_.get(), 0, this, 0);
disconnect(this, 0, artists_request_.get(), 0);
disconnect(artists_request_.get(), nullptr, this, nullptr);
disconnect(this, nullptr, artists_request_.get(), nullptr);
artists_request_.reset();
}
@@ -716,8 +731,8 @@ void TidalService::ArtistsUpdateProgressReceived(const int id, const int progres
void TidalService::ResetAlbumsRequest() {
if (albums_request_.get()) {
disconnect(albums_request_.get(), 0, this, 0);
disconnect(this, 0, albums_request_.get(), 0);
disconnect(albums_request_.get(), nullptr, this, nullptr);
disconnect(this, nullptr, albums_request_.get(), nullptr);
albums_request_.reset();
}
@@ -773,8 +788,8 @@ void TidalService::AlbumsUpdateProgressReceived(const int id, const int progress
void TidalService::ResetSongsRequest() {
if (songs_request_.get()) {
disconnect(songs_request_.get(), 0, this, 0);
disconnect(this, 0, songs_request_.get(), 0);
disconnect(songs_request_.get(), nullptr, this, nullptr);
disconnect(this, nullptr, songs_request_.get(), nullptr);
songs_request_.reset();
}

View File

@@ -247,6 +247,7 @@ class TidalService : public InternetService {
QStringList login_errors_;
QList<QObject*> wait_for_exit_;
QList<QNetworkReply*> replies_;
};

View File

@@ -57,7 +57,7 @@ TidalStreamURLRequest::TidalStreamURLRequest(TidalService *service, NetworkAcces
TidalStreamURLRequest::~TidalStreamURLRequest() {
if (reply_) {
disconnect(reply_, 0, this, 0);
disconnect(reply_, nullptr, this, nullptr);
if (reply_->isRunning()) reply_->abort();
reply_->deleteLater();
}
@@ -114,7 +114,7 @@ void TidalStreamURLRequest::GetStreamURL() {
++tries_;
if (reply_) {
disconnect(reply_, 0, this, 0);
disconnect(reply_, nullptr, this, nullptr);
if (reply_->isRunning()) reply_->abort();
reply_->deleteLater();
}
@@ -149,7 +149,7 @@ void TidalStreamURLRequest::GetStreamURL() {
void TidalStreamURLRequest::StreamURLReceived() {
if (!reply_) return;
disconnect(reply_, 0, this, 0);
disconnect(reply_, nullptr, this, nullptr);
reply_->deleteLater();
QByteArray data = GetReplyData(reply_, true);