diff -r 8e2727fc4e07 -r 42c6b071b231 libidav/webdav.c --- a/libidav/webdav.c Sat Feb 14 18:11:29 2026 +0100 +++ b/libidav/webdav.c Sat Jun 20 19:00:56 2026 +0200 @@ -41,6 +41,7 @@ #include #include "davqlparser.h" #include "davqlexec.h" +#include "atomic.h" DavContext* dav_context_new(void) { @@ -94,10 +95,22 @@ dav_context_destroy(context); return NULL; } + + context->ref = 1; return context; } +void dav_context_ref(DavContext *ctx) { + dav_atomic_inc32(&ctx->ref); +} + +void dav_context_unref(DavContext *ctx) { + if(dav_atomic_dec32(&ctx->ref) == 0) { + dav_context_destroy(ctx); + } +} + void dav_context_destroy(DavContext *ctx) { // destroy all sessions assoziated with this context // ctx->sessions destructor must be dav_session_destructor