Fixed potential resource leak

This commit is contained in:
Erik C. Thauvin 2023-01-31 22:07:20 -08:00
parent d525910145
commit a918fdf107

View file

@ -331,7 +331,7 @@ open class Akismet(apiKey: String) {
Request.Builder().url(apiUrl).post(formBody).header("User-Agent", buildUserAgent()).build()
}
try {
val result = client.newCall(request).execute()
client.newCall(request).execute().use { result ->
httpStatusCode = result.code
proTip = result.header("x-akismet-pro-tip", "").toString().trim()
isDiscard = (proTip == "discard")
@ -352,6 +352,7 @@ open class Akismet(apiKey: String) {
message
}
}
}
} catch (e: IOException) {
errorMessage = "An IO error occurred while communicating with the Akismet service: ${e.message}"
}