From 2ed9d165657d074b4576a58f88e05c8a1fee80b4 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 19 Apr 2025 19:40:24 +0200 Subject: [PATCH] fix crash caused by attachment bin_content cleanup --- application/attachment.c | 18 ++++++++++++++++-- application/types.h | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/application/attachment.c b/application/attachment.c index aaa1d55..85b39ff 100644 --- a/application/attachment.c +++ b/application/attachment.c @@ -85,16 +85,30 @@ void attachment_set_data(Attachment *attachment, cxmutstr data) { attachment->bin_content = data; } +static void attachment_save_result(UiEvent *event, int error, void *userdata) { + Attachment *attachment = userdata; + attachment->save_in_progress = FALSE; + if(!error) { + attachment->saved = TRUE; + attachment->content_saved = TRUE; + } else { + // TODO: error dialog? + } +} + /* * saves the attachment * * If cleanup_content is true, attachment->bin_content is set to NULL */ void attachment_save(UiObject *obj, Attachment *attachment, bool cleanup_content) { - if(!attachment->saved || !attachment->content_saved) { - note_store_save_attachment_async(obj, attachment, NULL, NULL); + if(!attachment->save_in_progress && !(attachment->saved || attachment->content_saved)) { + note_store_save_attachment_async(obj, attachment, attachment_save_result, attachment); + attachment->save_in_progress = FALSE; if(cleanup_content) { cxFree(attachment->ui->note_allocator, attachment->bin_content.ptr); + attachment->bin_content.ptr = NULL; + attachment->bin_content.length = 0; } } } diff --git a/application/types.h b/application/types.h index 50ed50e..d107db8 100644 --- a/application/types.h +++ b/application/types.h @@ -133,6 +133,9 @@ struct Attachment { // is the attachment persistently connected to a note bool saved; + // currently saving (async) + bool save_in_progress; + // ui AttachmentModel *ui; }; -- 2.43.5