File tigervnc-clean-pressed-key-on-exit.patch of Package tigervnc.141

diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx
index 40d08ae..7a571ec 100644
--- a/vncviewer/DesktopWindow.cxx
+++ b/vncviewer/DesktopWindow.cxx
@@ -186,6 +186,8 @@ DesktopWindow::~DesktopWindow()
 
   OptionsDialog::removeCallback(handleOptions);
 
+  delete viewport;
+
   // FLTK automatically deletes all child widgets, so we shouldn't touch
   // them ourselves here
 }
diff --git a/vncviewer/Viewport.cxx b/vncviewer/Viewport.cxx
index e308a63..41733f9 100644
--- a/vncviewer/Viewport.cxx
+++ b/vncviewer/Viewport.cxx
@@ -112,6 +112,11 @@ Viewport::Viewport(int w, int h, const rfb::PixelFormat& serverPF, CConn* cc_)
 
 Viewport::~Viewport()
 {
+  // Send release for every pressed key
+  for(DownMap::iterator iter = downKeySym.begin(); iter != downKeySym.end(); ++iter) {
+    cc->writer()->keyEvent(iter->second, false);
+  }
+
   // Unregister all timeouts in case they get a change tro trigger
   // again later when this object is already gone.
   Fl::remove_timeout(handleUpdateTimeout, this);
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index 37d63a6..5bb811d 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -83,6 +83,8 @@ char vncServerName[VNCSERVERNAMELEN] = { '\0' };
 static bool exitMainloop = false;
 static const char *exitError = NULL;
 
+static CConn *cc;
+
 void exit_vncviewer(const char *error)
 {
   // Prioritise the first error we get as that is probably the most
@@ -110,6 +112,16 @@ static void CleanupSignalHandler(int sig)
   // CleanupSignalHandler allows C++ object cleanup to happen because it calls
   // exit() rather than the default which is to abort.
   vlog.info("CleanupSignalHandler called");
+  delete cc;
+  exit(1);
+}
+
+static int CleanupXIOErrorHandler(Display *dpy)
+{
+  // CleanupSignalHandler allows C++ object cleanup to happen because it calls
+  // exit() rather than the default which is to abort.
+  vlog.info("XErrorHandler called");
+  delete cc;
   exit(1);
 }
 
@@ -384,6 +396,10 @@ int main(int argc, char** argv)
 
   init_fltk();
 
+  fl_open_display();
+
+  XSetIOErrorHandler(CleanupXIOErrorHandler);
+
   Configuration::enableViewerParams();
 
   /* Load the default parameter settings */
@@ -484,7 +500,7 @@ int main(int argc, char** argv)
 #endif
   }
 
-  CConn *cc = new CConn(vncServerName, sock);
+  cc = new CConn(vncServerName, sock);
 
   while (!exitMainloop) {
     int next_timer;
openSUSE Build Service is sponsored by