]> gitweb.factorcode.org Git - factor.git/commitdiff
odbc: use cleanup in odbc-query to prevent resource leaks on errors
authorAlexander Iljin <ajsoft@yandex.ru>
Sun, 30 Oct 2016 21:16:18 +0000 (00:16 +0300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 31 Oct 2016 01:59:10 +0000 (18:59 -0700)
extra/odbc/odbc.factor

index 6ae87d07e549b8b701e754aff907e905e404d9e5..57a14773c9fe01594f94bcffb6578799739b8b77 100644 (file)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2007 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien alien.c-types alien.data alien.libraries
-alien.strings alien.syntax combinators io.encodings.ascii kernel
-locals make math sequences strings threads ;
+alien.strings alien.syntax combinators continuations
+io.encodings.ascii kernel locals make math sequences strings
+threads ;
 FROM: alien.c-types => float short ;
 IN: odbc
 
@@ -259,8 +260,10 @@ C: <field> field
 
 : odbc-query ( string dsn -- result )
     odbc-init swap odbc-connect [
-        swap odbc-prepare
-        dup odbc-execute
-        dup odbc-get-all-rows
-        swap odbc-free-statement
-    ] keep odbc-disconnect ;
+        [
+            swap odbc-prepare
+            dup odbc-execute
+            dup odbc-get-all-rows
+            swap odbc-free-statement
+        ] keep
+    ] [ odbc-disconnect ] [ ] cleanup ;