Bug 5625: Fix OutOfMemoryError in YangStoreSnapshot 86/36886/2
authorTom Pantelis <tpanteli@brocade.com>
Tue, 29 Mar 2016 17:37:43 +0000 (13:37 -0400)
committerAnil Vishnoi <vishnoianil@gmail.com>
Wed, 30 Mar 2016 19:58:46 +0000 (19:58 +0000)
Close the InputStream returned via yangTextSchemaSource.openStream().

Change-Id: I3ecd2e1a3f52f91203a3a00c2f982b061cc62c42
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java

index 86dbb44a7ef4bb6580742730aa5e1b143a1c6923..677867091afc4f5c180675c39422acda7f4487b1 100644 (file)
@@ -16,6 +16,7 @@ import com.google.common.collect.Sets;
 import com.google.common.io.ByteStreams;
 import com.google.common.util.concurrent.CheckedFuture;
 import java.io.IOException;
+import java.io.InputStream;
 import java.lang.ref.SoftReference;
 import java.util.Collections;
 import java.util.HashMap;
@@ -156,7 +157,9 @@ final class YangStoreSnapshot implements YangStoreContext, EnumResolver {
 
         try {
             final YangTextSchemaSource yangTextSchemaSource = source.checkedGet();
-            return new String(ByteStreams.toByteArray(yangTextSchemaSource.openStream()), Charsets.UTF_8);
+            try(InputStream inStream = yangTextSchemaSource.openStream()) {
+                return new String(ByteStreams.toByteArray(inStream), Charsets.UTF_8);
+            }
         } catch (SchemaSourceException | IOException e) {
             LOG.warn("Unable to provide source for {}", moduleIdentifier, e);
             throw new IllegalArgumentException("Unable to provide source for " + moduleIdentifier, e);