Skip to content

Commit

Permalink
[lh 436] fixing potential connection leak when retrieving db URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ph2734 committed Jun 1, 2012
1 parent 37ce26d commit b083ffd
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions framework/src/play/src/main/scala/play/api/db/DB.scala
Expand Up @@ -44,8 +44,10 @@ trait DBApi {
* @throws an error if the required data source is not registered
*/
def getDataSourceURL(name: String): String = {
val ds = getDataSource(name)
ds.getConnection.getMetaData.getURL
val connection = getDataSource(name).getConnection
val url = connection.getMetaData.getURL
connection.close()
url
}

/**
Expand Down Expand Up @@ -199,6 +201,12 @@ class BoneCPPlugin(app: Application) extends DBPlugin {

lazy val dbConfig = app.configuration.getConfig("db").getOrElse(Configuration.empty)

private def dbURL(conn: Connection): String = {
val u = conn.getMetaData.getURL
conn.close()
u
}

// should be accessed in onStart first
private lazy val dbApi: DBApi = new BoneCPApi(dbConfig, app.classloader)

Expand All @@ -223,6 +231,7 @@ class BoneCPPlugin(app: Application) extends DBPlugin {
*/
def api: DBApi = dbApi


/**
* Reads the configuration and connects to every data source.
*/
Expand All @@ -233,7 +242,7 @@ class BoneCPPlugin(app: Application) extends DBPlugin {
ds._1.getConnection.close()
app.mode match {
case Mode.Test =>
case mode => Logger("play").info("database [" + ds._2 + "] connected at " + ds._1.getConnection.getMetaData.getURL)
case mode => Logger("play").info("database [" + ds._2 + "] connected at " + dbURL(ds._1.getConnection))
}
} catch {
case e => {
Expand Down

0 comments on commit b083ffd

Please sign in to comment.