From 7c164430ee2d6c61c9878b859462626de0960ae7 Mon Sep 17 00:00:00 2001 From: Ryan <2804894-ryannathans@users.noreply.gitlab.com> Date: Tue, 19 Apr 2022 11:58:11 +0000 Subject: [PATCH] fixed memleak in ge sqlite connection --- Server/src/main/kotlin/rs09/game/ge/GEDB.kt | 11 ++++------- Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Server/src/main/kotlin/rs09/game/ge/GEDB.kt b/Server/src/main/kotlin/rs09/game/ge/GEDB.kt index c5676d22d..c50b49e76 100644 --- a/Server/src/main/kotlin/rs09/game/ge/GEDB.kt +++ b/Server/src/main/kotlin/rs09/game/ge/GEDB.kt @@ -1,8 +1,6 @@ package rs09.game.ge import core.cache.def.impl.ItemDefinition -import core.game.ge.OfferState -import core.game.node.entity.player.link.audio.Audio import org.json.simple.JSONArray import org.json.simple.JSONObject import org.json.simple.parser.JSONParser @@ -10,17 +8,15 @@ import org.sqlite.SQLiteDataSource import rs09.ServerConstants import java.io.File import java.io.FileReader -import java.lang.Integer.min import java.sql.Connection -import java.sql.DriverManager /** * Collection of methods for interacting with the grand exchange databases * @author Ceikry */ object GEDB { - var pathString = "" - var connection: Connection? = null + private var pathString = "" + private var connection: Connection? = null //This needs to be a separate method, so we can call it after the server config has been parsed fun init() @@ -34,7 +30,7 @@ object GEDB { fun connect(): Connection { - if(connection == null || connection?.isClosed == true) + if (connection == null || connection!!.isClosed) { val ds = SQLiteDataSource() ds.url = "jdbc:sqlite:$pathString" @@ -161,5 +157,6 @@ object GEDB { statement.execute("insert into price_index(item_id, value) values(${def.id},${def.value})") } } + statement.close() } } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt b/Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt index 3a364e54f..aae056b75 100644 --- a/Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt +++ b/Server/src/main/kotlin/rs09/game/ge/GrandExchange.kt @@ -104,6 +104,7 @@ class GrandExchange : StartupListener { if(offer.amountLeft != before) SystemLogger.logGE("Purchased FROM BOT ${offer.amountLeft - before}x ${getItemName(offer.itemID)}") } + botStmt.close() } sellStmt.close() }