wasm: saveFile(): copy data before returning

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 <even.oscar.andersen@qt.io>
Reviewed-by: Piotr Wierciński <piotr.wiercinski@qt.io>
This commit is contained in:
Morten Sørvig 2024-06-10 23:43:25 +02:00 committed by Morten Johan Sørvig
parent 9768d8e1ba
commit 4b32420243

View File

@ -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);
},
});
}