Fix crash in destructor of Data::CloudFile.

This commit is contained in:
John Preston 2020-06-03 13:48:11 +04:00
parent 63c6a1db82
commit f88b97553e
3 changed files with 11 additions and 2 deletions

View File

@ -16,6 +16,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Data { namespace Data {
CloudFile::~CloudFile() {
// Destroy loader with still alive CloudFile with already zero '.loader'.
// Otherwise in ~FileLoader it tries to clear file.loader and crashes.
base::take(loader);
}
void CloudImageView::set( void CloudImageView::set(
not_null<Main::Session*> session, not_null<Main::Session*> session,
QImage image) { QImage image) {
@ -224,7 +230,8 @@ void LoadCloudFile(
} }
// NB! file.loader may be in ~FileLoader() already. // NB! file.loader may be in ~FileLoader() already.
if (const auto loader = base::take(file.loader)) { if (const auto loader = base::take(file.loader)) {
if (file.flags & CloudFile::Flag::Cancelled) { if ((file.flags & CloudFile::Flag::Cancelled)
&& !loader->cancelled()) {
loader->cancel(); loader->cancel();
} }
} }

View File

@ -34,6 +34,8 @@ struct CloudFile final {
}; };
friend inline constexpr bool is_flag_type(Flag) { return true; }; friend inline constexpr bool is_flag_type(Flag) { return true; };
~CloudFile();
ImageLocation location; ImageLocation location;
std::unique_ptr<FileLoader> loader; std::unique_ptr<FileLoader> loader;
int byteSize = 0; int byteSize = 0;

@ -1 +1 @@
Subproject commit 6451ae50741a13b6b8e48835da654e24f34695aa Subproject commit 30d223befe328ff697b3af879ef69c514d21c5f3