Thu, 16 Apr 2026 17:41:35 +0200
allow NULL as ctx in ui_malloc functions
| ui/common/context.c | file | annotate | diff | comparison | revisions |
--- a/ui/common/context.c Thu Apr 16 17:36:41 2026 +0200 +++ b/ui/common/context.c Thu Apr 16 17:41:35 2026 +0200 @@ -692,26 +692,30 @@ } void* ui_malloc(UiContext *ctx, size_t size) { - return ctx ? cxMalloc(ctx->allocator, size) : NULL; + return ctx ? cxMalloc(ctx->allocator, size) : malloc(size); } void* ui_calloc(UiContext *ctx, size_t nelem, size_t elsize) { - return ctx ? cxCalloc(ctx->allocator, nelem, elsize) : NULL; + return ctx ? cxCalloc(ctx->allocator, nelem, elsize) : calloc(nelem, elsize); } void ui_free(UiContext *ctx, void *ptr) { - if(ctx && ptr) { - cxFree(ctx->allocator, ptr); + if(ptr) { + if(ctx) { + cxFree(ctx->allocator, ptr); + } else { + free(ptr); + } } } void* ui_realloc(UiContext *ctx, void *ptr, size_t size) { - return ctx ? cxRealloc(ctx->allocator, ptr, size) : NULL; + return ctx ? cxRealloc(ctx->allocator, ptr, size) : realloc(ptr, size); } char* ui_strdup(UiContext *ctx, const char *str) { if(!ctx) { - return NULL; + return strdup(str ? str : ""); } cxstring s = cx_str(str); cxmutstr d = cx_strdup_a(ctx->allocator, s);