Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt/curl: fix segfault in curl #9595

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 24 additions & 6 deletions rpcs3/rpcs3qt/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,31 @@ usz curl_write_cb_compat(char* ptr, usz /*size*/, usz nmemb, void* userdata)
downloader::downloader(QWidget* parent)
: QObject(parent)
, m_parent(parent)
, m_curl(new curl_handle(this))
{
m_curl = new curl_handle(this);
connect(this, &downloader::signal_buffer_update, this, &downloader::handle_buffer_update);
}

downloader::~downloader()
{
m_curl_abort = true;
if (m_thread && m_thread->isRunning())
{
m_thread->wait();
}
}

void downloader::start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title, bool keep_progress_dialog_open, int exptected_size)
{
connect(this, &downloader::signal_buffer_update, this, &downloader::handle_buffer_update);
if (m_thread)
{
m_curl_abort = true;
if (m_thread->isRunning())
{
m_thread->wait();
}
m_thread->deleteLater();
}

m_keep_progress_dialog_open = keep_progress_dialog_open;
m_curl_buf.clear();
Expand All @@ -36,7 +54,7 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
curl_easy_setopt(m_curl->get_curl(), CURLOPT_WRITEDATA, this);
curl_easy_setopt(m_curl->get_curl(), CURLOPT_FOLLOWLOCATION, follow_location ? 1 : 0);

const auto thread = QThread::create([this]
m_thread = QThread::create([this]
{
const auto result = curl_easy_perform(m_curl->get_curl());
m_curl_success = result == CURLE_OK;
Expand All @@ -49,7 +67,7 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
}
});

connect(thread, &QThread::finished, this, [this]()
connect(m_thread, &QThread::finished, this, [this]()
{
if (m_curl_abort)
{
Expand Down Expand Up @@ -95,8 +113,8 @@ void downloader::start(const std::string& url, bool follow_location, bool show_p
}
}

thread->setObjectName("Compat Update");
thread->start();
m_thread->setObjectName("Download Thread");
m_thread->start();
}

void downloader::update_progress_dialog(const QString& title)
Expand Down
5 changes: 4 additions & 1 deletion rpcs3/rpcs3qt/downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class downloader : public QObject
Q_OBJECT

public:
downloader(QWidget* parent = nullptr);
explicit downloader(QWidget* parent = nullptr);
~downloader();

void start(const std::string& url, bool follow_location, bool show_progress_dialog, const QString& progress_dialog_title = "", bool keep_progress_dialog_open = false, int expected_size = -1);
usz update_buffer(char* data, usz size);
Expand Down Expand Up @@ -43,4 +44,6 @@ private Q_SLOTS:
progress_dialog* m_progress_dialog = nullptr;
atomic_t<bool> m_keep_progress_dialog_open = false;
QString m_progress_dialog_title;

QThread* m_thread = nullptr;
};