Fixed Crapup resulting in a crash when no connection is available and it
gets launched twice before connection expires
This commit is contained in:
Valentino Orlandi 2023-01-27 02:08:41 +01:00
parent 526dfb4137
commit b98c97735f
Signed by: elB4RTO
GPG Key ID: 1719E976DB2D4E71
1 changed files with 24 additions and 20 deletions

View File

@ -30,32 +30,39 @@ Crapup::Crapup( const int& window_theme_id, const QString& icons_theme, QWidget*
Crapup::~Crapup()
{
delete this->ui;
if ( this->reply ) {
delete this->reply;
if ( this->ui != nullptr ) {
delete this->ui;
this->ui = nullptr;
}
if ( this->img_timer ) {
if ( this->reply != nullptr ) {
this->deleteReply();
}
if ( this->img_timer != nullptr ) {
delete this->img_timer;
this->img_timer = nullptr;
}
if ( this->request_timer ) {
if ( this->request_timer != nullptr ) {
delete this->request_timer;
this->request_timer = nullptr;
}
}
void Crapup::closeEvent( QCloseEvent* event )
{
this->quitting = true;
if ( this->img_timer->isActive() ) {
this->img_timer->stop();
}
if ( this->request_timer->isActive() ) {
this->request_timer->stop();
}
if ( this->reply ) {
if ( !this->reply->isFinished() ) {
this->requestTimeout();
if ( this->img_timer != nullptr ) {
if ( this->img_timer->isActive() ) {
this->img_timer->stop();
}
}
if ( this->request_timer != nullptr ) {
if ( this->request_timer->isActive() ) {
this->request_timer->stop();
}
}
if ( this->reply != nullptr ) {
this->requestTimeout();
}
}
@ -104,8 +111,8 @@ void Crapup::versionCheck( const float v )
// reply waiter loop
QEventLoop wait_reply;
connect(this->reply, SIGNAL(readyRead()), &wait_reply, SLOT(quit()));
connect(this, SIGNAL(abortRequest()), &wait_reply, SLOT(quit()));
connect(this->reply, &QNetworkReply::readyRead, &wait_reply, &QEventLoop::quit);
connect(this, &Crapup::abortRequest, &wait_reply, &QEventLoop::quit);
// make the request
this->request_timer->start( this->timeout_msec+1000 );
@ -254,11 +261,8 @@ void Crapup::requestTimeout()
void Crapup::deleteReply()
{
if ( !this->reply->isFinished() ) {
this->reply->abort();
}
if ( this->reply->isOpen() ) {
this->reply->close();
this->reply->abort();
}
delete this->reply;
this->reply = nullptr;