Sun, 17 Sep 2023 11:21:31 +0200
fix dav_context_destroy
libidav/session.c | file | annotate | diff | comparison | revisions | |
libidav/webdav.c | file | annotate | diff | comparison | revisions | |
libidav/webdav.h | file | annotate | diff | comparison | revisions |
--- a/libidav/session.c Thu Sep 14 18:11:50 2023 +0200 +++ b/libidav/session.c Sun Sep 17 11:21:31 2023 +0200 @@ -302,8 +302,13 @@ ssize_t i = cxListFind(sessions, sn); if(i >= 0) { cxListRemove(sessions, i); + } else { + printf("Error: session not found in ctx->sessions\n"); + dav_session_destructor(sn); } - +} + +void dav_session_destructor(DavSession *sn) { cxMempoolDestroy(sn->mp); curl_easy_cleanup(sn->handle); free(sn);
--- a/libidav/webdav.c Thu Sep 14 18:11:50 2023 +0200 +++ b/libidav/webdav.c Sun Sep 17 11:21:31 2023 +0200 @@ -51,6 +51,7 @@ return NULL; } context->sessions = cxLinkedListCreate(cxDefaultAllocator, cx_cmp_intptr, CX_STORE_POINTERS); + context->sessions->destructor_data = dav_session_destructor; context->http_proxy = calloc(1, sizeof(DavProxy)); if(!context->http_proxy) { dav_context_destroy(context); @@ -100,11 +101,9 @@ void dav_context_destroy(DavContext *ctx) { // destroy all sessions assoziated with this context - CxIterator i = cxListIterator(ctx->sessions); - cx_foreach(DavSession*, sn, i) { - dav_session_destroy(sn); - } + // ctx->sessions destructor must be dav_session_destructor cxListDestroy(ctx->sessions); + if(ctx->http_proxy) { free(ctx->http_proxy); } @@ -113,7 +112,7 @@ } if(ctx->namespaces) { - i = cxMapIteratorValues(ctx->namespaces); + CxIterator i = cxMapIteratorValues(ctx->namespaces); cx_foreach(DavNamespace*, ns, i) { if(!ns) continue; if(ns->prefix) { @@ -130,7 +129,7 @@ // TODO: implement } if(ctx->keys) { - i = cxMapIteratorValues(ctx->keys); + CxIterator i = cxMapIteratorValues(ctx->keys); cx_foreach(DavKey*, key, i) { if(!key) continue; if(key->name) {
--- a/libidav/webdav.h Thu Sep 14 18:11:50 2023 +0200 +++ b/libidav/webdav.h Sun Sep 17 11:21:31 2023 +0200 @@ -276,6 +276,8 @@ void dav_session_destroy(DavSession *sn); +void dav_session_destructor(DavSession *sn); + void* dav_session_malloc(DavSession *sn, size_t size); void* dav_session_calloc(DavSession *sn, size_t nelm, size_t size); void* dav_session_realloc(DavSession *sn, void *ptr, size_t size);