diff --git a/gnome-pty-helper/gnome-pty-helper.c b/gnome-pty-helper/gnome-pty-helper.c
index dcd3a10..dec537f 100644
--- a/gnome-pty-helper/gnome-pty-helper.c
+++ b/gnome-pty-helper/gnome-pty-helper.c
@@ -94,19 +94,10 @@ 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;
+        return 0;
 }
 
 static int
@@ -115,6 +106,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 +116,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)
