--- a/libidav/crypto.c Fri May 30 18:21:16 2025 +0200 +++ b/libidav/crypto.c Fri May 30 18:31:32 2025 +0200 @@ -858,7 +858,6 @@ void dav_sha256_final(DAV_SHA_CTX *ctx, unsigned char *buf) { CC_SHA256_Final(buf, ctx); - free(ctx); } DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) { @@ -1426,7 +1425,7 @@ DAV_SHA_CTX *ctx = dav_sha256_create(); if(ctx) { dav_sha256_update(ctx, data, len); - dav_sha256_final(ctx, hash); + dav_sha256_final_free(ctx, hash); } return util_hexstr(hash, DAV_SHA256_DIGEST_LENGTH); } @@ -1452,7 +1451,6 @@ // cleanup cng_cleanup(ctx->hAlg, NULL, ctx->hHash, ctx->pbHashObject); - free(ctx); } DavKey* dav_pw2key(const char *password, const unsigned char *salt, int saltlen, int pwfunc, int enc) { @@ -1518,7 +1516,10 @@ } #endif - +void dav_sha256_final_free(DAV_SHA_CTX *ctx, unsigned char *buf) { + dav_sha256_final(ctx, buf); + free(ctx); +} CxBuffer* aes_encrypt_buffer(CxBuffer *in, DavKey *key) { CxBuffer *encbuf = cxBufferCreate(NULL, in->size, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);