Skip to content

Commit 8f31c4e

Browse files
committed
Workaround crash with GCC 12 (#539)
When co_await and lambda with captures are used in the same expression, GCC 12 bug causes double free. Use another runOnThreadPool overload that takes Args... which creates lambda outside of coroutine, so that this bug is not triggered.
1 parent 51b0843 commit 8f31c4e

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44
### Fixed
55
- Black screen issues when closing fullscreen window on macOS
6+
- Crash with GCC 12
67

78
## [2.7.2] - 2024-09-15
89
### Fixed

src/rpc/requestrouter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ namespace tremotesf::impl {
330330
RequestRouter::onRequestSuccess(NetworkReplyUniquePtr reply, RpcRequestMetadata metadata) {
331331
debug()
332332
.log("HTTP request for method '{}' succeeded, HTTP status: {}", metadata.method, httpStatus(reply.get()));
333-
const auto json =
334-
co_await runOnThreadPool(mThreadPool, [reply = std::move(reply)]() -> std::optional<QJsonObject> {
333+
const auto json = co_await runOnThreadPool(
334+
[](NetworkReplyUniquePtr reply) -> std::optional<QJsonObject> {
335335
const auto replyData = reply->readAll();
336336
QJsonParseError error{};
337337
QJsonObject json = QJsonDocument::fromJson(replyData, &error).object();
@@ -345,7 +345,9 @@ namespace tremotesf::impl {
345345
return {};
346346
}
347347
return json;
348-
});
348+
},
349+
std::move(reply)
350+
);
349351
if (!json.has_value()) {
350352
emit requestFailed(RpcError::ParseError, {}, {});
351353
cancelCoroutine();

src/ui/screens/torrentproperties/torrentfilesmodel.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ namespace tremotesf {
206206
mCreatingTree = true;
207207
beginResetModel();
208208

209-
auto self = QPointer(this);
210-
211-
auto [rootDirectory, files] =
212-
co_await runOnThreadPool([files = std::vector(mTorrent->files())]() { return doCreateTree(files); });
209+
auto [rootDirectory, files] = co_await runOnThreadPool(
210+
[](const std::vector<TorrentFile>& files) { return doCreateTree(files); },
211+
mTorrent->files()
212+
);
213213

214214
mRootDirectory = std::move(rootDirectory);
215215
endResetModel();

0 commit comments

Comments
 (0)