Skip to content

Commit 698c861

Browse files
Use sqlite3_close_v2 instead of sqlite3_close for improved cleanup
1 parent d60f1f0 commit 698c861

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

sqlcipher/src/main/jni/sqlcipher/android_database_SQLiteConnection.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,22 @@ static jlong nativeOpen(JNIEnv* env, jclass clazz, jstring pathStr, jint openFla
211211
err = sqlite3_create_collation(db, "localized", SQLITE_UTF8, 0, coll_localized);
212212
if (err != SQLITE_OK) {
213213
throw_sqlite3_exception_errcode(env, err, "Could not register collation");
214-
sqlite3_close(db);
214+
sqlite3_close_v2(db);
215215
return 0;
216216
}
217217

218218
// Check that the database is really read/write when that is what we asked for.
219219
if ((sqliteFlags & SQLITE_OPEN_READWRITE) && sqlite3_db_readonly(db, NULL)) {
220220
throw_sqlite3_exception(env, db, "Could not open the database in read/write mode.");
221-
sqlite3_close(db);
221+
sqlite3_close_v2(db);
222222
return 0;
223223
}
224224

225225
// Set the default busy handler to retry automatically before returning SQLITE_BUSY.
226226
err = sqlite3_busy_timeout(db, BUSY_TIMEOUT_MS);
227227
if (err != SQLITE_OK) {
228228
throw_sqlite3_exception(env, db, "Could not set busy timeout");
229-
sqlite3_close(db);
229+
sqlite3_close_v2(db);
230230
return 0;
231231
}
232232

@@ -253,10 +253,10 @@ static void nativeClose(JNIEnv* env, jclass clazz, jlong connectionPtr) {
253253

254254
if (connection) {
255255
ALOGV("Closing connection %p", connection->db);
256-
int err = sqlite3_close(connection->db);
256+
int err = sqlite3_close_v2(connection->db);
257257
if (err != SQLITE_OK) {
258258
// This can happen if sub-objects aren't closed first. Make sure the caller knows.
259-
ALOGE("sqlite3_close(%p) failed: %d", connection->db, err);
259+
ALOGE("sqlite3_close_v2(%p) failed: %d", connection->db, err);
260260
throw_sqlite3_exception(env, connection->db, "Count not close db.");
261261
return;
262262
}
@@ -967,9 +967,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
967967

968968
android::gpJavaVM = vm;
969969
vm->GetEnv((void**)&env, JNI_VERSION_1_4);
970-
971970
setEnvarToCacheDirectory(env, "SQLCIPHER_TMP");
972-
973971
android::register_android_database_SQLiteConnection(env);
974972
android::register_android_database_SQLiteDebug(env);
975973
android::register_android_database_SQLiteGlobal(env);

0 commit comments

Comments
 (0)