Skip to content

修复 Xcode16 编译运行 iOS18 sqlite3_finalize 闪退问题 #166

@li6185377

Description

@li6185377

修复Xcode16编译引起的闪退,在 iOS18 中,需要提前对 sqlite3_stmt 执行 sqlite3_finalize

@implementation YYKVStorage

- (BOOL)_dbClose {
   ...
// 原代码
    if (_dbStmtCache) CFRelease(_dbStmtCache);

// 替换为
    if (_dbStmtCache) {              
        CFIndex size = CFDictionaryGetCount(_dbStmtCache);
        CFTypeRef *valuesRef = (CFTypeRef *)malloc(size * sizeof(CFTypeRef));
        CFDictionaryGetKeysAndValues(_dbStmtCache, NULL, (const void **)valuesRef);
        const sqlite3_stmt **stmts = (const sqlite3_stmt **)valuesRef;
        for (CFIndex i = 0; i < size; i ++) {
            sqlite3_stmt *stmt = (sqlite3_stmt *)stmts[i];
            sqlite3_finalize(stmt);
        }
        free(valuesRef);
        CFRelease(_dbStmtCache);
    }
    ...
}

@end

建议改用 CFDictionaryApplyFunction 更加优雅: #163

该 pull request 还有对 WAL 膨胀的治理。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions