From f4d762c19bab0784404dd2b9c833e9bd69cac02b Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 3 Oct 2019 08:09:11 +1000 Subject: [PATCH] fix not closing the db connection after opening --- .../FirefoxBookmarks.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/Plugins/Wox.Plugin.BrowserBookmark/FirefoxBookmarks.cs b/Plugins/Wox.Plugin.BrowserBookmark/FirefoxBookmarks.cs index 67c8b1f78c..7686501cd7 100644 --- a/Plugins/Wox.Plugin.BrowserBookmark/FirefoxBookmarks.cs +++ b/Plugins/Wox.Plugin.BrowserBookmark/FirefoxBookmarks.cs @@ -27,20 +27,25 @@ namespace Wox.Plugin.BrowserBookmark if (string.IsNullOrEmpty(PlacesPath) || !File.Exists(PlacesPath)) return new List(); + var bookmarList = new List(); + // create the connection string and init the connection - string dbPath = string.Format(dbPathFormat, PlacesPath); - var dbConnection = new SQLiteConnection(dbPath); - - // Open connection to the database file and execute the query - dbConnection.Open(); - var reader = new SQLiteCommand(queryAllBookmarks, dbConnection).ExecuteReader(); - - // return results in List format - return reader.Select(x => new Bookmark() + string dbPath = string.Format(dbPathFormat, PlacesPath); + using (var dbConnection = new SQLiteConnection(dbPath)) { - Name = (x["title"] is DBNull) ? string.Empty : x["title"].ToString(), - Url = x["url"].ToString() - }).ToList(); + // Open connection to the database file and execute the query + dbConnection.Open(); + var reader = new SQLiteCommand(queryAllBookmarks, dbConnection).ExecuteReader(); + + // return results in List format + bookmarList = reader.Select(x => new Bookmark() + { + Name = (x["title"] is DBNull) ? string.Empty : x["title"].ToString(), + Url = x["url"].ToString() + }).ToList(); + } + + return bookmarList; } ///