Module Name:    src
Committed By:   christos
Date:           Wed Mar 19 18:11:17 UTC 2014

Modified Files:
        src/sys/kern: tty_ptm.c

Log Message:
fix leak on error from pty_fill_ptmget (Ilya Zykov)


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/kern/tty_ptm.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/tty_ptm.c
diff -u src/sys/kern/tty_ptm.c:1.29 src/sys/kern/tty_ptm.c:1.30
--- src/sys/kern/tty_ptm.c:1.29	Sun Mar 16 01:20:30 2014
+++ src/sys/kern/tty_ptm.c	Wed Mar 19 14:11:17 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty_ptm.c,v 1.29 2014/03/16 05:20:30 dholland Exp $	*/
+/*	$NetBSD: tty_ptm.c,v 1.30 2014/03/19 18:11:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.29 2014/03/16 05:20:30 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.30 2014/03/19 18:11:17 christos Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_ptm.h"
@@ -381,7 +381,9 @@ ptmioctl(dev_t dev, u_long cmd, void *da
 			goto bad;
 
 		/* now, put the indices and names into struct ptmget */
-		return pty_fill_ptmget(l, newdev, cfd, sfd, data);
+		if ((error = pty_fill_ptmget(l, newdev, cfd, sfd, data)) != 0)
+			goto bad2;
+		return 0;
 	default:
 #ifdef COMPAT_60
 		error = compat_60_ptmioctl(dev, cmd, data, flag, l);
@@ -391,6 +393,11 @@ ptmioctl(dev_t dev, u_long cmd, void *da
 		DPRINTF(("ptmioctl EINVAL\n"));
 		return EINVAL;
 	}
+bad2:
+	fp = fd_getfile(sfd);
+	if (fp != NULL) {
+		fd_close(sfd);
+	}
  bad:
 	fp = fd_getfile(cfd);
 	if (fp != NULL) {

Reply via email to