--- newt-0.51.6/form.c.orig	2004-10-15 11:17:35.042333181 -0400
+++ newt-0.51.6/form.c	2004-10-15 11:18:53.428533351 -0400
@@ -889,6 +889,7 @@
     struct eventResult er;
     int key, i, max;
     int done = 0;
+    int success;
     fd_set readSet, writeSet, exceptSet;
     struct timeval nextTimeout, now, timeout;
 #ifdef USE_GPM
@@ -902,7 +903,7 @@
     conn.minMod      = 0;
     conn.maxMod      = 0;
 
-    Gpm_Open(&conn, 0);
+    success = Gpm_Open(&conn, 0);
 #endif
 
     newtFormSetSize(co);
@@ -1062,7 +1063,8 @@
     }
     newtRefresh();
 #ifdef USE_GPM
-    Gpm_Close();
+    if (success > 0)
+        Gpm_Close();
 #endif
 }
 
