* lib/sha3.c (sha3_free_ctx): Preserve errno.
* modules/crypto/sha3 (Depends-on):
* modules/crypto/sha3-buffer (Depends-on):
Depend on free-posix.
---
 ChangeLog                  | 6 ++++++
 lib/sha3.c                 | 2 ++
 modules/crypto/sha3        | 1 +
 modules/crypto/sha3-buffer | 1 +
 4 files changed, 10 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 47606778bc..cabca53248 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2026-02-22  Paul Eggert  <[email protected]>
 
+       crypto/sha3: fix errno when freeing
+       * lib/sha3.c (sha3_free_ctx): Preserve errno.
+       * modules/crypto/sha3 (Depends-on):
+       * modules/crypto/sha3-buffer (Depends-on):
+       Depend on free-posix.
+
        crypto/sha3: fix memory leak with OpenSSL wrapper
        * lib/sha3.c (sha3_##SIZE##_buffer):
        Free ctx before returning.
diff --git a/lib/sha3.c b/lib/sha3.c
index f7ca3c4abb..2a97190e07 100644
--- a/lib/sha3.c
+++ b/lib/sha3.c
@@ -364,8 +364,10 @@ sha3_free_ctx (struct sha3_ctx *ctx)
 {
   if (ctx->evp_ctx != NULL)
     {
+      int saved_errno = errno;
       EVP_MD_CTX_free (ctx->evp_ctx);
       ctx->evp_ctx = NULL;
+      errno = saved_errno;
     }
 }
 
diff --git a/modules/crypto/sha3 b/modules/crypto/sha3
index f2b878794a..50e2ead34f 100644
--- a/modules/crypto/sha3
+++ b/modules/crypto/sha3
@@ -7,6 +7,7 @@ lib/sha3-stream.c
 Depends-on:
 crypto/af_alg
 crypto/sha3-buffer
+free-posix
 
 configure.ac:
 
diff --git a/modules/crypto/sha3-buffer b/modules/crypto/sha3-buffer
index 7ab61dea30..00c2f230a4 100644
--- a/modules/crypto/sha3-buffer
+++ b/modules/crypto/sha3-buffer
@@ -11,6 +11,7 @@ Depends-on:
 bool
 byteswap
 c99
+free-posix
 stddef-h
 stdint-h
 u64
-- 
2.51.0


Reply via email to