Fix for memory leak In SmbSession

Fixes https://github.com/spring-projects/spring-integration-extensions/issues/225

If SmbShare instantiates a BaseContext during construction then the
context will be closed on calling close().

Without this there's a ThreadLocal memory leak
This commit is contained in:
Adam Jones
2020-06-22 22:54:35 +01:00
committed by GitHub
parent b06e9968be
commit 48c27e3fea
2 changed files with 22 additions and 3 deletions

View File

@@ -406,7 +406,7 @@ public class SmbSession implements Session<SmbFile> {
@Override
public void close() {
this.smbShare.doClose();
this.smbShare.close();
}
/**

View File

@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import jcifs.CIFSContext;
import jcifs.CIFSException;
import jcifs.config.PropertyConfiguration;
import jcifs.context.BaseContext;
import jcifs.context.SingletonContext;
@@ -49,6 +50,8 @@ public class SmbShare extends SmbFile {
private final AtomicBoolean useTempFile = new AtomicBoolean(false);
private final AtomicBoolean closeContext = new AtomicBoolean(false);
/**
* @deprecated as of release 1.1.0, use {@link #SmbShare(SmbConfig)} instead.
* @param url do not use
@@ -98,6 +101,8 @@ public class SmbShare extends SmbFile {
new PropertyConfiguration(_props)).withCredentials(
new NtlmPasswordAuthenticator(
_smbConfig.getDomain(), _smbConfig.getUsername(), _smbConfig.getPassword())));
this.closeContext.set(true);
}
public void init() throws NestedIOException {
@@ -142,11 +147,25 @@ public class SmbShare extends SmbFile {
}
/**
* Set the open state to closed.
* Note: jcifs.smb.SmbFile defines a package-protected method close().
* @deprecated use {@link #close()} instead.
*/
@Deprecated
void doClose() {
close();
}
@Override
public synchronized void close() {
this.open.set(false);
if (this.closeContext.get()) {
try {
getContext().close();
}
catch (CIFSException e) {
logger.error("Unable to close share: " + this);
}
}
super.close();
}
public String newTempFileSuffix() {