diff options
author | 2024-09-20 20:19:05 +0300 | |
---|---|---|
committer | 2024-09-20 20:23:58 +0300 | |
commit | 1c4644bc7f5b27a76bb97bf4f55dfce8a2cf228f (patch) | |
tree | 84f8fd15c431bc243941ee4cf1cf16cda6ee1338 /src/cache.cpp | |
parent | dd38d9021e4da20b26a20a6b54e7ca7047bf2b6c (diff) | |
download | newsboat-1c4644bc7f5b27a76bb97bf4f55dfce8a2cf228f.tar.gz newsboat-1c4644bc7f5b27a76bb97bf4f55dfce8a2cf228f.tar.zst newsboat-1c4644bc7f5b27a76bb97bf4f55dfce8a2cf228f.zip |
Avoid UB by unlocking Cache mutex before destroying it
Credit to Dennis van der Schagt for figuring it out:
https://github.com/newsboat/newsboat/issues/2783#issuecomment-2325308102
Fixes #2783.
Diffstat (limited to '')
-rw-r--r-- | src/cache.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/cache.cpp b/src/cache.cpp index e15055a0..ec69e44b 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -284,6 +284,12 @@ Cache::Cache(const std::string& cachefile, ConfigContainer* c) Cache::~Cache() { sqlite3_close(db); + + // Destroying a locked mutex is undefined behaviour, so: + // 1. ensure the mutex is locked (either by us or by `cleanup_cache()`) + // 2. unlock it + mtx.try_lock(); + mtx.unlock(); } void Cache::set_pragmas() |