fix new UiModel reference counter

Thu, 16 Apr 2026 17:36:41 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 16 Apr 2026 17:36:41 +0200
changeset 1090
ab2e458df182
parent 1089
a3db51a94b37
child 1091
1524b5dc4d4d

fix new UiModel reference counter

ui/common/types.c file | annotate | diff | comparison | revisions
--- a/ui/common/types.c	Wed Apr 15 11:19:25 2026 +0200
+++ b/ui/common/types.c	Thu Apr 16 17:36:41 2026 +0200
@@ -224,6 +224,7 @@
 UiModel* ui_model(UiContext *ctx, ...) {
     UiModel *info = ui_calloc(ctx, 1, sizeof(UiModel));
     info->ctx = ctx;
+    info->ref = 1;
     
     va_list ap;
     va_start(ap, ctx);
@@ -275,6 +276,7 @@
 UiModel* ui_model_new(UiContext *ctx) {
     UiModel *info = ui_calloc(ctx, 1, sizeof(UiModel));
     info->ctx = ctx;
+    info->ref = 1;
     info->alloc = UI_MODEL_DEFAULT_ALLOC_SIZE;
     info->types = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(UiModelType));
     info->titles = ui_calloc(ctx, UI_MODEL_DEFAULT_ALLOC_SIZE, sizeof(char*));
@@ -371,7 +373,7 @@
 
 void ui_model_free(UiModel *mi) {
     UiContext *ctx = mi->ctx;
-    const CxAllocator* a = ctx->allocator;
+    const CxAllocator* a = ctx ? ctx->allocator : cxDefaultAllocator;
     for(int i=0;i<mi->columns;i++) {
         ui_free(ctx, mi->titles[i]);
     }

mercurial