diff --git a/gnome-pty-helper/gnome-pty-helper.c b/gnome-pty-helper/gnome-pty-helper.c
index dcd3a10..a8a259f 100644
--- a/gnome-pty-helper/gnome-pty-helper.c
+++ b/gnome-pty-helper/gnome-pty-helper.c
@@ -94,20 +94,16 @@ static pty_info *pty_list;
 #endif
 #endif /* CMSG_DATA */
 
-static struct cmsghdr *cmptr;
-static int CONTROLLEN;
-
-static int
-init_msg_pass (void)
-{
-	CONTROLLEN = (CMSG_DATA (cmptr) - (unsigned char *)cmptr) + sizeof(int);
-	cmptr = malloc (CONTROLLEN);
-
-	if (cmptr)
-		return 0;
-
-	return -1;
-}
+/* Solaris doesn't define these */
+#ifndef CMSG_ALIGN
+#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))
+#endif
+#ifndef CMSG_SPACE
+#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr)))
+#endif
+#ifndef CMSG_LEN
+#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
+#endif
 
 static int
 pass_fd (int client_fd, int fd)
@@ -115,6 +111,8 @@ pass_fd (int client_fd, int fd)
         struct iovec  iov[1];
         struct msghdr msg;
         char          buf [1];
+        char    cmsgbuf[CMSG_SPACE(sizeof(int))];
+        struct  cmsghdr *cmptr;
 
 	iov [0].iov_base = buf;
 	iov [0].iov_len  = 1;
@@ -123,12 +121,13 @@ pass_fd (int client_fd, int fd)
 	msg.msg_iovlen     = 1;
 	msg.msg_name       = NULL;
 	msg.msg_namelen    = 0;
-	msg.msg_control    = (caddr_t) cmptr;
-	msg.msg_controllen = CONTROLLEN;
+	msg.msg_control    = (caddr_t) cmsgbuf;
+	msg.msg_controllen = sizeof(cmsgbuf);
 
+        cmptr = CMSG_FIRSTHDR(&msg);
 	cmptr->cmsg_level = SOL_SOCKET;
 	cmptr->cmsg_type  = SCM_RIGHTS;
-	cmptr->cmsg_len   = CONTROLLEN;
+	cmptr->cmsg_len   = CMSG_LEN(sizeof(int));
 	*(int *)CMSG_DATA (cmptr) = fd;
 
 	if (sendmsg (client_fd, &msg, 0) != 1)
@@ -153,12 +152,6 @@ pass_fd (int client_fd, int fd)
 #include <sys/uio.h>
 
 static int
-init_msg_pass ()
-{
-  return 0;
-}
-
-static int
 pass_fd (int client_fd, int fd)
 {
   struct iovec  iov[1];
@@ -184,12 +177,6 @@ pass_fd (int client_fd, int fd)
 #else
 #include <stropts.h>
 #ifdef I_SENDFD
-static int
-init_msg_pass ()
-{
-	/* nothing */
-	return 0;
-}
 
 int
 pass_fd (int client_fd, int fd)
@@ -707,9 +694,6 @@ main (int argc, char *argv [])
 	signal (SIGHUP, exit_handler);
 	signal (SIGTERM, exit_handler);
 
-	if (init_msg_pass () == -1)
-		exit (1);
-
 	while (!done) {
 		res = n_read (STDIN_FILENO, &op, sizeof (op));
 
