From: Tom Pantelis Date: Tue, 29 Mar 2016 17:37:43 +0000 (-0400) Subject: Bug 5625: Fix OutOfMemoryError in YangStoreSnapshot X-Git-Tag: release/boron~263 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=990c36b8a92ffb36b0b386855f6a7ea79e5ea226 Bug 5625: Fix OutOfMemoryError in YangStoreSnapshot Close the InputStream returned via yangTextSchemaSource.openStream(). Change-Id: I3ecd2e1a3f52f91203a3a00c2f982b061cc62c42 Signed-off-by: Tom Pantelis --- diff --git a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java index 86dbb44a7e..677867091a 100644 --- a/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java +++ b/opendaylight/config/config-manager-facade-xml/src/main/java/org/opendaylight/controller/config/facade/xml/osgi/YangStoreSnapshot.java @@ -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);