$NetBSD: patch-am,v 1.1 2006/12/19 07:53:57 wiz Exp $

plugged fd leaks.

http://mlterm.cvs.sourceforge.net/mlterm/mlterm/mlterm/ml_config_menu.c?r1=1.6&r2=1.7&view=patch

--- mlterm/ml_config_menu.c.orig	2003/09/16 03:18:31	1.6
+++ mlterm/ml_config_menu.c	2006/10/19 14:41:51	1.7
@@ -33,6 +33,7 @@
 	if( config_menu->pid == pid)
 	{
 		config_menu->pid = 0 ;
+		close( config_menu->fd) ;
 		config_menu->fd = -1 ;
 	}
 }
@@ -83,6 +84,12 @@
 		return  0 ;
 	}
 
+	if( !kik_file_unset_cloexec( pty_fd))
+	{
+		/* configulators require an inherited pty. */
+		return  0 ;
+	}
+
 	if( pipe( fds) == -1)
 	{
 		return  0 ;
@@ -131,8 +138,14 @@
 
 		close( fds[1]) ;
 
-		if( dup2( fds[0] , STDIN_FILENO) == -1 || dup2( pty_fd , STDOUT_FILENO) == -1 ||
-			execv( cmd_path , args) == -1)
+		/* for configulators,
+		 * STDIN => to read replys from mlterm
+		 * STDOUT => to write the "master" side of pty
+		 * STDERR => is retained to be the mlterm's STDERR
+		 */
+		if( dup2( fds[0] , STDIN_FILENO) == -1
+		 || dup2( pty_fd , STDOUT_FILENO) == -1
+	       	 || execv( cmd_path , args) == -1)
 		{
 			/* failed */
 
@@ -148,6 +161,9 @@
 
 	config_menu->fd = fds[1] ;
 	config_menu->pid = pid ;
+	
+	kik_file_set_cloexec( pty_fd) ;
+	kik_file_set_cloexec( config_menu->fd) ;
 
 	return  1 ;
 }
