]> uap-core.de Git - note.git/commitdiff
fix crash caused by attachment bin_content cleanup
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 19 Apr 2025 17:40:24 +0000 (19:40 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 19 Apr 2025 17:40:24 +0000 (19:40 +0200)
application/attachment.c
application/types.h

index aaa1d558c65c9ff62e210486e7e678dee10bfa42..85b39ff2afc8711657c4a081b0dad1ab9f61eef6 100644 (file)
@@ -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;
         }
     }
 }
index 50ed50eed04cf6b53554b0bbcf8224f4f70ceebd..d107db8a88396de5be300ee6e22f2c8e638e07e8 100644 (file)
@@ -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;
 };