Closed siren186 closed 2 months ago
WCDB has disabled c++ exception. You can check -fno-exceptions compile option in CMakeLists.
WCDB 应该是:面对调用者代码有异常产生时,保证:
针对以上两点,WCDB 中发现以下两处代码,无法保证异常安全:
原因在于:调用外部传入的回调函数后,外部用户代码抛出异常,造成紧跟在该回调函数后面的 WCDB 内部代码 rollbackTransaction
或 commitOrRollbackTransaction
未被执行到,从而导致 WCDB 内部资源未正确回收。
建议在调用该外部回调函数之前,加一个 XXXGuard guard;
临时变量,在变量的析构函数中,释放相关资源。
这样无论外部调用者再怎么抛异常,WCDB 内部都不会出任何问题。异常安全得到保证!
// 析构函数伪代码
~XXXGuard() {
if (m_succeed) {
commitOrRollbackTransaction();
} else {
rollbackTransaction();
}
}
附: Visual Studio 2019 并不支持编译选项:-fno-exceptions,以下是相关编译日志
warning D9002: 忽略未知选项“-fno-exceptions”
There are lots of details should be considered to support C++ exception, I don't plan to do that for now.
I recommend you to disable C++ exception, which will make the compiled result much smaller.
The language of WCDB
The version of WCDB
The platform of WCDB
The installation of WCDB
What's the issue?
这个BUG是随机的,以下代码几乎必现。出问题的位置也很随机,会随机出现崩溃、死锁等。 以下是复现代码: