Browse Source

r5138 did not completely resolve the problem with clipboard data consuming too much heap space. Large amounts of clipboard data could still cause the heap size to grow to huge sizes. This patch tries to address the problem by opening a Reader to the underlying IO stream and then reading only up to MaxCutText characters. The garbage collector is invoked manually rather than waiting for the JVM to do it in order to prevent the heap size from growing in between JVM invoked garbage collections.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5155 3789f03b-4d11-0410-bbf8-ca57d06f2519
tags/v1.3.90
Brian Hinz 10 years ago
parent
commit
d121c1430d

+ 5
- 0
java/com/tigervnc/vncviewer/ClipboardDialog.java View File

pack(); pack();
} }


public boolean compareContentsTo(String str) {
return str.equals(textArea.getText());

}

public void setContents(String str) { public void setContents(String str) {
textArea.setText(str); textArea.setText(str);
} }

+ 22
- 20
java/com/tigervnc/vncviewer/DesktopWindow.java View File

import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.io.BufferedReader;
import java.nio.CharBuffer;
import javax.swing.*; import javax.swing.*;


import com.tigervnc.rfb.*; import com.tigervnc.rfb.*;
try { try {
if (sm != null) sm.checkSystemClipboardAccess(); if (sm != null) sm.checkSystemClipboardAccess();
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
if (cb == null) return;
Transferable t = cb.getContents(null);
if ((t != null) && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
try {
String newContents = new String("");
if (t.getTransferData(DataFlavor.stringFlavor) != null) {
int len = Math.min(cc.viewer.maxCutText.getValue(),
((String)t.getTransferData(DataFlavor.stringFlavor)).length());
newContents =
((String)t.getTransferData(DataFlavor.stringFlavor)).substring(0, len);
}
if (!newContents.equals(cc.clipboardDialog.getContents())) {
if (cc.viewer.sendClipboard.getValue())
cc.writeClientCutText(newContents, newContents.length());
cc.clipboardDialog.setContents(newContents);
}
} catch(java.lang.Exception e) {
vlog.debug("Exception getting clipboard data: " + e.getMessage());
if (cb != null) {
Transferable t = cb.getContents(null);
if (t == null) return;
DataFlavor flavor =
DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
if (flavor == null) return;
BufferedReader br = new BufferedReader(flavor.getReaderForText(t));
CharBuffer cbuf =
CharBuffer.allocate(VncViewer.maxCutText.getValue());
br.read(cbuf);
cbuf.flip();
String newContents = cbuf.toString();
if (!cc.clipboardDialog.compareContentsTo(newContents)) {
cc.clipboardDialog.setContents(newContents);
if (cc.viewer.sendClipboard.getValue())
cc.writeClientCutText(newContents, newContents.length());
} }
br.close();
System.gc();
} }
} catch(SecurityException e) {
vlog.debug("Cannot access the system clipboard");
} catch(java.lang.Exception e) {
vlog.debug("Exception getting clipboard data: " + e.getMessage());
} }
} }



+ 1
- 1
java/com/tigervnc/vncviewer/VncViewer.java View File

= new BoolParameter("SendClipboard", = new BoolParameter("SendClipboard",
"Send clipboard changes to the server", "Send clipboard changes to the server",
true); true);
IntParameter maxCutText
static IntParameter maxCutText
= new IntParameter("MaxCutText", = new IntParameter("MaxCutText",
"Maximum permitted length of an outgoing clipboard update", "Maximum permitted length of an outgoing clipboard update",
262144); 262144);

Loading…
Cancel
Save