Skip to content

Commit 38624e9

Browse files
committed
fix error
1 parent 89cf577 commit 38624e9

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Sources/Otter/SQLiteCode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,6 @@ public enum SQLiteCode: Int32, Error {
125125

126126
func throwing(_ rc: Int32, connection: OpaquePointer? = nil) throws(OtterError) {
127127
guard rc != SQLITE_OK, let code = SQLiteCode(rawValue: rc) else { return }
128+
// Memory for the error is managed by SQLite so we don't need to free it.
128129
throw .sqlite(code, String(cString: sqlite3_errmsg(connection)))
129130
}

Sources/Otter/SQLiteConnection.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ class SQLiteConnection: @unchecked Sendable {
4040
return
4141
}
4242

43-
let message = error.map { String(cString: $0) }
43+
var message: String?
44+
if let error {
45+
message = String(cString: error)
46+
sqlite3_free(error)
47+
}
48+
4449
throw .sqlite(SQLiteCode(rc), message)
4550
}
4651

0 commit comments

Comments
 (0)