Don't invoke sqlite3_db_release_memory on closed database connections

This commit is contained in:
Gwendal Roué committed 2024-09-04 09:21:30 +02:00
1 parent f4b4035704
commit cdb181d9ca
3 files changed
+18 -1

No files matched your search

+3 -1
View File
@@ -1575,7 +1575,9 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib
/// Frees as much memory as possible.
public func releaseMemory() {
SchedulingWatchdog.preconditionValidQueue(self)
sqlite3_db_release_memory(sqliteConnection)
if let sqliteConnection {
sqlite3_db_release_memory(sqliteConnection)
}
schemaCache.clear()
internalStatementCache.clear()
publicStatementCache.clear()
+8
View File
@@ -439,4 +439,12 @@ class DatabasePoolTests: GRDBTestCase {
// In the zombie state, closing is a noop
try dbPool.close()
}
// Regression test for <https://github.com/groue/GRDB.swift/issues/1612>
func test_releaseMemory_after_close() throws {
let dbPool = try makeDatabasePool()
try dbPool.read { _ in } // Create a reader
try dbPool.close()
dbPool.releaseMemory()
}
}
+7
View File
@@ -467,4 +467,11 @@ class DatabaseQueueTests: GRDBTestCase {
try db.execute(sql: "SELECT * FROM sqlite_master")
}
}
// Regression test for <https://github.com/groue/GRDB.swift/issues/1612>
func test_releaseMemory_after_close() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.close()
dbQueue.releaseMemory()
}
}