# Sqlcipher\_extra\_shutdown() is holding Mutex during sqlcipher\_atexit

**URL:** <https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908>\
**Category:** Issues\
**Created:** [May 7, 2025, 6:37am UTC](https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908 "2025-05-07T06:37:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deb](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@Deb](https://discuss.zetetic.net/u/Deb)\
**Post date:** [May 7, 2025, 6:37am UTC](https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908/1 "2025-05-07T06:37:30Z")

</div>

Hey Experts,  
Can you share any insights on the following?

Here is the stack being flagged by Appverifier as one holding lock. Working on test application that uses encrypter.dll, in which I have wrapper class over SqlCipher, this is allocated as global variable.

encrypter!winMutexInit+0x6A  
encrypter!sqlite3MutexInit+0x111  
encrypter!sqlite3\_mutex\_alloc+0x35  
encrypter!sqlcipher\_extra\_shutdown+0x30  
encrypter!sqlcipher\_atexit+0x34  
encrypter!\<lambda\_d121dba8a4adeaf3a9819e48611155df\>::operator()+0x129  
encrypter!\_\_crt\_seh\_guarded\_call::operator()\<\<lambda\_6a47f4c8fd0152770a780fc1d70204eb\>,\<lambda\_d121dba8a4adeaf3a9819e48611155df\> &,\<lambda\_6aaa2265f5b6a89667e7d7630012e97a\> \>+0x35  
encrypter!\_\_acrt\_lock\_and\_call\<\<lambda\_d121dba8a4adeaf3a9819e48611155df\> \>+0x57  
encrypter!\_execute\_onexit\_table+0x34  
encrypter!\<lambda\_6e4b09c48022b2350581041d5f6b0c4c\>::operator()+0x95  
encrypter!\_\_crt\_seh\_guarded\_call::operator()\<\<lambda\_d80eeec6fff315bfe5c115232f3240e3\>,\<lambda\_6e4b09c48022b2350581041d5f6b0c4c\> &,\<lambda\_2358e3775559c9db80273638284d5e45\> \>+0x2D  
encrypter!\_\_acrt\_lock\_and\_call\<\<lambda\_6e4b09c48022b2350581041d5f6b0c4c\> \>+0x57  
encrypter!common\_exit+0x70  
encrypter!\_cexit+0x13  
encrypter!\_\_scrt\_dllmain\_uninitialize\_c+0x2A  
encrypter!dllmain\_crt\_process\_detach+0x4D  
encrypter!dllmain\_crt\_dispatch+0x67  
encrypter!dllmain\_dispatch+0xFF  
encrypter!\_DllMainCRTStartup+0x32  
verifier!AVrfpStandardDllEntryPointRoutine+0xE9

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [May 7, 2025, 9:22pm UTC](https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908/2 "2025-05-07T21:22:02Z")

</div>

Hello @Deb - In this case, sqlcipher\_extra\_shutdown is obtaining a lock so it can proceed with cleanup of sqlcipher library internals. A mutex is used to ensure that access is properly synchronized. We have not observed problems with this in the past. Can you please explain the specific problem you are facing in more detail?

---

<div class="post-metadata">

**Author:** ![Deb](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@Deb](https://discuss.zetetic.net/u/Deb)\
**Post date:** [May 7, 2025, 11:15pm UTC](https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908/3 "2025-05-07T23:15:58Z")

</div>

Problem:  
With SqlCipher 4.7.0, application verifier flags my application, saying it is holding lock inside global variable.  
Same code works good with older version 4.6.1 but I do not want to use it since it is older.

---

<div class="post-metadata">

**Author:** ![Deb](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@Deb](https://discuss.zetetic.net/u/Deb)\
**Post date:** [May 8, 2025, 7:55pm UTC](https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908/4 "2025-05-08T19:55:13Z")

</div>

Can the following be fix for the problem?

After below line, calling **sqlite3\_mutex\_free(mutex);**

> <https://github.com/sqlcipher/sqlcipher/blob/ab47245fc9b7ee078b679ff4a7e18dc23c42e636/src/sqlcipher.c#L667>

In other words can code be as below?

cleanup:  
sqlcipher\_init = 0;  
sqlcipher\_init\_error = SQLITE\_ERROR;  
sqlcipher\_shutdown = 1;  
if(mutex) {  
sqlite3\_mutex\_leave(mutex);  
[[sqlite3\_mutex\_free(mutex);]] =\> This being the fix ?  
}

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [May 8, 2025, 9:00pm UTC](https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908/5 "2025-05-08T21:00:03Z")

</div>

@Deb No, I don’t think that is the proper solution. The mutex in question is an internal static mutex and should not be freed like that.

We’re still looking into this. Can you provide a small standalone project that reproduces this problem so we can troubleshoot further? If so, please email it to [support@zetetic.net](mailto:support@zetetic.net). That is the quickest way to assist and get resolution.

---

<div class="post-metadata">

**Author:** ![sjlombardo](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.zetetic.net/sjlombardo/32/3_2.png) [@sjlombardo](https://discuss.zetetic.net/u/sjlombardo)\
**Post date:** [May 15, 2025, 7:50pm UTC](https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908/6 "2025-05-15T19:50:44Z")

</div>

@Deb please try this with SQLCipher 4.9.0.

---

<div class="post-metadata">

**Author:** ![Deb](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@Deb](https://discuss.zetetic.net/u/Deb)\
**Post date:** [May 20, 2025, 6:13pm UTC](https://discuss.zetetic.net/t/sqlcipher-extra-shutdown-is-holding-mutex-during-sqlcipher-atexit/6908/7 "2025-05-20T18:13:48Z")

</div>

SQLCipher 4.9.0 solves the problem for me.  
Thank you! Stephen for helping out.
