diff --git a/changelog.html b/changelog.html
index ccb3197bf5..c92901547f 100644
--- a/changelog.html
+++ b/changelog.html
@@ -63,6 +63,9 @@ Upcoming changes
+ -
+ Fixed random OutOfMemoryError with console annotations
+ (issue 9349)
-
Repeated ids, expandTextArea() and multiple "Invoke Ant" build steps.
(issue 10989)
diff --git a/core/src/main/java/hudson/console/AnnotatedLargeText.java b/core/src/main/java/hudson/console/AnnotatedLargeText.java
index 9bf93a5a8f..cd64f64cf3 100644
--- a/core/src/main/java/hudson/console/AnnotatedLargeText.java
+++ b/core/src/main/java/hudson/console/AnnotatedLargeText.java
@@ -121,10 +121,14 @@ public class AnnotatedLargeText extends LargeText {
ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(
new CipherInputStream(new ByteArrayInputStream(Base64.decode(base64.toCharArray())),sym)),
Jenkins.getInstance().pluginManager.uberClassLoader);
- long timestamp = ois.readLong();
- if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp))
- // don't deserialize something too old to prevent a replay attack
- return (ConsoleAnnotator)ois.readObject();
+ try {
+ long timestamp = ois.readLong();
+ if (TimeUnit2.HOURS.toMillis(1) > abs(System.currentTimeMillis()-timestamp))
+ // don't deserialize something too old to prevent a replay attack
+ return (ConsoleAnnotator)ois.readObject();
+ } finally {
+ ois.close();
+ }
}
} catch (GeneralSecurityException e) {
throw new IOException2(e);
diff --git a/core/src/main/java/hudson/console/ConsoleNote.java b/core/src/main/java/hudson/console/ConsoleNote.java
index ccc6710640..4731f2aba6 100644
--- a/core/src/main/java/hudson/console/ConsoleNote.java
+++ b/core/src/main/java/hudson/console/ConsoleNote.java
@@ -222,7 +222,11 @@ public abstract class ConsoleNote implements Serializable, Describable