From 20a9dcbdbdb316d9e7ab492ec54647778879f299 Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Mon, 22 Oct 2012 13:18:52 -0400 Subject: [PATCH] db: fix finalization bug (cherry picked from commit 8226899df387629babc5a7bf7ffbcdbac4f237be) --- collects/db/private/odbc/connection.rkt | 9 ++++++++- collects/db/private/sqlite3/connection.rkt | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/collects/db/private/odbc/connection.rkt b/collects/db/private/odbc/connection.rkt index 30414008f9..5f23a1c5c2 100644 --- a/collects/db/private/odbc/connection.rkt +++ b/collects/db/private/odbc/connection.rkt @@ -656,7 +656,14 @@ #:on-notice add-notice!))) (super-new) - (register-finalizer this (lambda (obj) (send obj disconnect))))) + (register-finalizer this + (lambda (obj) + ;; Keep a reference to the class to keep all FFI callout objects + ;; (eg, SQLDisconnect) used by its methods from being finalized. + (let ([dont-gc this%]) + (send obj disconnect) + ;; Dummy result to prevent reference from being optimized away + dont-gc))))) ;; ---------------------------------------- diff --git a/collects/db/private/sqlite3/connection.rkt b/collects/db/private/sqlite3/connection.rkt index 5a716249cc..a4d04423fb 100644 --- a/collects/db/private/sqlite3/connection.rkt +++ b/collects/db/private/sqlite3/connection.rkt @@ -316,7 +316,14 @@ ;; ---- (super-new) - (register-finalizer this (lambda (obj) (send obj disconnect))))) + (register-finalizer this + (lambda (obj) + ;; Keep a reference to the class to keep all FFI callout objects + ;; (eg, sqlite3_close) used by its methods from being finalized. + (let ([dont-gc this%]) + (send obj disconnect) + ;; Dummy result to prevent reference from being optimized away + dont-gc))))) ;; ----------------------------------------