Subject: x2goclient 4.0.5.0 (and 4.0.5.1 preview) frequent ssh commands don't free resources

From: Mat Martineau <[email-masked]>
Date: Wed, 17 Feb 2016 09:00:44 -0800 (PST)

I've run in to this problem as well, with these x2go versions:

Client (Mac)
  * x2goclient 4.0.5.0 (OS X 10.9+ build) or 4.0.5.1 preview (December 2015 
build)
  * OS X 10.11.3
  * XQuartz 2.7.8

Server (Linux)
  * x2goagent: 3.5.0.32
  * x2goserver: 4.0.1.19
  * x2goserver-extensions: 4.0.1.19
  * Fedora 23 (with updates as of 2016-02-17)

Steps to reproduce:
  1. Run 'x2goclient --debug' and open a session
  2. Observe frequent xmodmap commands while session is active
  3. Quit session to see a large number of SshProcess objects freed

This came to my attention because the default SELinux/audit settings on 
Fedora 23 log five events for each xmodmap ssh command executed on the 
server by the client. That's 1800 events per hour when an x2go session is 
active.

Judging from ONMainWindow::slotSetModMap() in onmainwindow.cpp, it looks 
like the intent is to only run the xmodmap command if kbMap is empty 
(maybe there's an expected way for kbMap to get cleared so it has to be 
periodically checked?). However, slotSetModMap() runs every 10 seconds and 
executes a command every time. It's not clear to me how kbMap becomes 
empty.

Furthermore, the SshProcess objects are not cleaned up until the session 
is exited. The 'processes' QList in SshMasterConnection grows without 
bound.

Logs from x2goclient --debug:

"""
x2go-DEBUG-../src/sshprocess.cpp:199> Executing remote command via 
SshProcess object 6: "export DISPLAY=":50"; echo "keycode   8 = a A aring 
Aring
<snip>"
x2go-DEBUG-../src/sshprocess.cpp:204> Running 
masterCon->addChannelConnection(this, 
'"d93c9f1a-2d4d-42fb-92a9-5373621768f6"', '"bash -c 'echo 
"X2GODATABEGIN:d93c9f1a-2d4d-42fb-92a9-5373621768f6"; export 
PATH="/usr/local/bin:/usr/bin:/bin"; export DISPLAY=":50"; echo "keycode 
8 = a A aring Aring
keycode   9 = s S ssharp Iacut"');
x2go-DEBUG-../src/sshmasterconnection.cpp:1284> Locking SSH channel 
connection MUTEX.
x2go-DEBUG-../src/sshmasterconnection.cpp:1286> Passing new channel 
conenction object to channelConnections.
x2go-DEBUG-../src/sshmasterconnection.cpp:1288> Unlocking SSH channel 
connection MUTEX.
x2go-DEBUG-../src/sshmasterconnection.cpp:1476> Creating new channel.

x2go-DEBUG-../src/sshmasterconnection.cpp:1480> New channel:0x7fcb9a7af450

x2go-DEBUG-../src/sshmasterconnection.cpp:1511> Executing remote: "bash -c 
'echo "X2GODATABEGIN:d93c9f1a-2d4d-42fb-92a9-5373621768f6"; export 
PATH="/usr/local/bin:/usr/bin:/bin"; export DISPLAY=":50"; echo "keycode 
8 = a A aring Aring
<snip>"
x2go-DEBUG-../src/sshmasterconnection.cpp:1534> New exec channel created.

x2go-DEBUG-../src/sshmasterconnection.cpp:1638> EOF on channel 
0x7fcb9a7af450; SshProcess object: 6
x2go-DEBUG-../src/sshmasterconnection.cpp:1706> EOF sent.
x2go-DEBUG-../src/sshmasterconnection.cpp:1710> Channel closed.
x2go-DEBUG-../src/sshprocess.cpp:517> SSH finished: raw output (stdout): 
"X2GODATABEGIN:d93c9f1a-2d4d-42fb-92a9-5373621768f6
X2GODATAEND:d93c9f1a-2d4d-42fb-92a9-5373621768f6
"
x2go-DEBUG-../src/sshprocess.cpp:528> SSH finished: true - "" (6).
<repeat every 10 seconds>
"""

And the log of SshProcess cleanup when the session is disconnected after a 
little over one minute:

"""
x2go-DEBUG-../src/sshmasterconnection.cpp:715> SshMasterConnection, 
instance SshMasterConnection(0x7fcb9cc51a90)  thread finished.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshprocess.cpp:52> SshProcess destructor called.
x2go-DEBUG-../src/sshmasterconnection.cpp:722> SshMasterConnection, 
instance SshMasterConnection(0x7fcb9cc51a90)  finished destructor. 
"""

--
Mat Martineau
Intel OTC