]> source.dussan.org Git - jackcess.git/commitdiff
cleanup stream on database open failure
authorJames Ahlborn <jtahlborn@yahoo.com>
Wed, 7 Apr 2010 12:22:59 +0000 (12:22 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Wed, 7 Apr 2010 12:22:59 +0000 (12:22 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@461 f203690c-595d-4dc9-a70b-905162fa7fd2

src/java/com/healthmarketscience/jackcess/Database.java

index 5dadac1b9a30a9a19200a6eb5fbe1618e9d6af8a..9ea72bf2e394c27a4550e0a53b529c4a7b3be848 100644 (file)
@@ -476,15 +476,30 @@ public class Database
                      FileFormat fileFormat)
     throws IOException
   {
-    _format = JetFormat.getFormat(channel);
-    _fileFormat = fileFormat;
-    _pageChannel = new PageChannel(channel, _format, autoSync);
-    // note, it's slighly sketchy to pass ourselves along partially
-    // constructed, but only our _format and _pageChannel refs should be
-    // needed
-    _pageChannel.initialize(this);
-    _buffer = _pageChannel.createPageBuffer();
-    readSystemCatalog();
+    boolean success = false;
+    try {
+
+      _format = JetFormat.getFormat(channel);
+      _fileFormat = fileFormat;
+      _pageChannel = new PageChannel(channel, _format, autoSync);
+      // note, it's slighly sketchy to pass ourselves along partially
+      // constructed, but only our _format and _pageChannel refs should be
+      // needed
+      _pageChannel.initialize(this);
+      _buffer = _pageChannel.createPageBuffer();
+      readSystemCatalog();
+      success = true;
+
+    } finally {
+      if(!success && (channel != null)) {
+        // something blew up, shutdown the channel (quietly)
+        try {
+          channel.close();
+        } catch(Exception ignored) {
+          // we don't care
+        }
+      }
+    }
   }
   
   public PageChannel getPageChannel() {