From 4b324202433365ff43f623903beefc4286345839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 10 Jun 2024 23:43:25 +0200 Subject: [PATCH] wasm: saveFile(): copy data before returning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make saveFile(char *, size) make an immediate copy of the data also for the case where we use a save file dialog. Previously it would make a copy after the file dialog was closed, but at that point the content pointer may be stale if the calling code did not keep it alive. This makes the behavior for the two save code paths be identical: a copy of the data will be made right away, before the function returns. This is also the only behavior which makes sense, since the function has no way of communicating to the caller when it is done with the data. Pick-to: 6.6 6.7 6.8 Change-Id: I890a4897f20251e9abbf90d0a4b96d8ba12d3740 Reviewed-by: Even Oscar Andersen Reviewed-by: Piotr WierciƄski --- src/gui/platform/wasm/qwasmlocalfileaccess.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/platform/wasm/qwasmlocalfileaccess.cpp b/src/gui/platform/wasm/qwasmlocalfileaccess.cpp index a946cda043f..051e2b1a04e 100644 --- a/src/gui/platform/wasm/qwasmlocalfileaccess.cpp +++ b/src/gui/platform/wasm/qwasmlocalfileaccess.cpp @@ -277,9 +277,10 @@ void saveFile(const char *content, size_t size, const std::string &fileNameHint) return; } + QByteArray data(content, size); FileDialog::showSave(fileNameHint, { .thenFunc = [=](emscripten::val result) { - saveDataToFileInChunks(result, QByteArray(content, size)); + saveDataToFileInChunks(result, data); }, }); }