From f2dcd99cca731fe6ef0a61ca6a9d64872439febf Mon Sep 17 00:00:00 2001 From: Peter Valchev Date: Thu, 14 Feb 2002 22:57:19 +0000 Subject: More FREF/FRELE fixes --- sys/compat/svr4/svr4_stream.c | 93 +++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 35 deletions(-) (limited to 'sys/compat/svr4') diff --git a/sys/compat/svr4/svr4_stream.c b/sys/compat/svr4/svr4_stream.c index 2f3cd8e7d32..09828a6ffce 100644 --- a/sys/compat/svr4/svr4_stream.c +++ b/sys/compat/svr4/svr4_stream.c @@ -1,4 +1,4 @@ -/* $OpenBSD: svr4_stream.c,v 1.15 2002/02/13 19:08:06 art Exp $ */ +/* $OpenBSD: svr4_stream.c,v 1.16 2002/02/14 22:57:18 pvalchev Exp $ */ /* $NetBSD: svr4_stream.c,v 1.19 1996/12/22 23:00:03 fvdl Exp $ */ /* @@ -1428,17 +1428,18 @@ svr4_sys_putmsg(p, v, retval) if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL) return EBADF; + FREF(fp); if (SCARG(uap, ctl) != NULL) { if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) - return error; + goto out; } else ctl.len = -1; if (SCARG(uap, dat) != NULL) { if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) - return error; + goto out; } else dat.len = -1; @@ -1448,23 +1449,26 @@ svr4_sys_putmsg(p, v, retval) */ if ((st = svr4_stream_get(fp)) == NULL) { DPRINTF(("putmsg: bad file type\n")); - return EINVAL; + error = EINVAL; + goto out; } if (ctl.len > sizeof(sc)) { DPRINTF(("putmsg: Bad control size %d != %d\n", ctl.len, sizeof(struct svr4_strmcmd))); - return EINVAL; + error = EINVAL; + goto out; } if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0) - return error; + goto out; switch (st->s_family) { case AF_INET: if (sc.len != sizeof(sain)) { DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len)); - return ENOSYS; + error = ENOSYS; + goto out; } netaddr_to_sockaddr_in(&sain, &sc); skp = &sain; @@ -1477,7 +1481,8 @@ svr4_sys_putmsg(p, v, retval) /* We are doing an accept; succeed */ DPRINTF(("putmsg: Do nothing\n")); *retval = 0; - return 0; + error = 0; + goto out; } else { /* Maybe we've been given a device/inode pair */ dev_t *dev = SVR4_ADDROF(&sc); @@ -1495,14 +1500,15 @@ svr4_sys_putmsg(p, v, retval) default: DPRINTF(("putmsg: Unsupported address family %d\n", st->s_family)); - return ENOSYS; + error = ENOSYS; + goto out; } sg = stackgap_init(p->p_emul); sup = stackgap_alloc(&sg, sasize); if ((error = copyout(skp, sup, sasize)) != 0) - return error; + goto out; switch (st->s_cmd = sc.cmd) { case SVR4_TI_CONNECT_REQUEST: /* connect */ @@ -1512,7 +1518,8 @@ svr4_sys_putmsg(p, v, retval) SCARG(&co, s) = SCARG(uap, fd); SCARG(&co, name) = (void *)sup; SCARG(&co, namelen) = (int)sasize; - return sys_connect(p, &co, retval); + error = sys_connect(p, &co, retval); + goto out; } case SVR4_TI_SENDTO_REQUEST: /* sendto */ @@ -1532,13 +1539,18 @@ svr4_sys_putmsg(p, v, retval) SCARG(uap, flags), retval); *retval = 0; - return error; + goto out; } default: DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd)); - return ENOSYS; + error = ENOSYS; + goto out; } + +out: + FRELE(fp); + return (error); } @@ -1576,10 +1588,11 @@ svr4_sys_getmsg(p, v, retval) if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL) return EBADF; + FREF(fp); if (SCARG(uap, ctl) != NULL) { if ((error = copyin(SCARG(uap, ctl), &ctl, sizeof(ctl))) != 0) - return error; + goto out; } else { ctl.len = -1; @@ -1588,7 +1601,7 @@ svr4_sys_getmsg(p, v, retval) if (SCARG(uap, dat) != NULL) { if ((error = copyin(SCARG(uap, dat), &dat, sizeof(dat))) != 0) - return error; + goto out; } else { dat.len = -1; @@ -1600,12 +1613,14 @@ svr4_sys_getmsg(p, v, retval) */ if ((st = svr4_stream_get(fp)) == NULL) { DPRINTF(("getmsg: bad file type\n")); - return EINVAL; + error = EINVAL; + goto out; } if (ctl.maxlen == -1 || dat.maxlen == -1) { DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n")); - return ENOSYS; + error = ENOSYS; + goto out; } switch (st->s_family) { @@ -1622,7 +1637,8 @@ svr4_sys_getmsg(p, v, retval) default: DPRINTF(("getmsg: Unsupported address family %d\n", st->s_family)); - return ENOSYS; + error = ENOSYS; + goto out; } sg = stackgap_init(p->p_emul); @@ -1631,7 +1647,7 @@ svr4_sys_getmsg(p, v, retval) fl = sasize; if ((error = copyout(&fl, flen, sizeof(fl))) != 0) - return error; + goto out; switch (st->s_cmd) { case SVR4_TI_CONNECT_REQUEST: @@ -1662,11 +1678,11 @@ svr4_sys_getmsg(p, v, retval) if ((error = sys_getpeername(p, &ga, retval)) != 0) { DPRINTF(("getmsg: getpeername failed %d\n", error)); - return error; + goto out; } if ((error = copyin(sup, skp, sasize)) != 0) - return error; + goto out; sc.cmd = SVR4_TI_CONNECT_REPLY; sc.pad[0] = 0x4; @@ -1686,7 +1702,8 @@ svr4_sys_getmsg(p, v, retval) break; default: - return ENOSYS; + error = ENOSYS; + goto out; } ctl.len = 40; @@ -1721,7 +1738,7 @@ svr4_sys_getmsg(p, v, retval) if ((error = sys_accept(p, &aa, retval)) != 0) { DPRINTF(("getmsg: accept failed %d\n", error)); - return error; + goto out; } st->s_afd = *retval; @@ -1729,7 +1746,7 @@ svr4_sys_getmsg(p, v, retval) DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd)); if ((error = copyin(sup, skp, sasize)) != 0) - return error; + goto out; sc.cmd = SVR4_TI_ACCEPT_REPLY; sc.len = sasize; @@ -1755,7 +1772,8 @@ svr4_sys_getmsg(p, v, retval) break; default: - return ENOSYS; + error = ENOSYS; + goto out; } ctl.len = 40; @@ -1773,7 +1791,7 @@ svr4_sys_getmsg(p, v, retval) ctl.len = sizeof(sc); if ((error = copyin(ctl.buf, &sc, ctl.len)) != 0) - return error; + goto out; switch (st->s_family) { case AF_INET: @@ -1785,7 +1803,8 @@ svr4_sys_getmsg(p, v, retval) break; default: - return ENOSYS; + error = ENOSYS; + goto out; } msg.msg_name = (caddr_t) sup; @@ -1801,11 +1820,11 @@ svr4_sys_getmsg(p, v, retval) if (error) { DPRINTF(("getmsg: recvit failed %d\n", error)); - return error; + goto out; } if ((error = copyin(msg.msg_name, skp, sasize)) != 0) - return error; + goto out; sc.cmd = SVR4_TI_RECVFROM_REPLY; @@ -1821,7 +1840,8 @@ svr4_sys_getmsg(p, v, retval) break; default: - return ENOSYS; + error = ENOSYS; + goto out; } dat.len = *retval; @@ -1832,26 +1852,27 @@ svr4_sys_getmsg(p, v, retval) default: st->s_cmd = sc.cmd; DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd)); - return EINVAL; + error = EINVAL; + goto out; } if (SCARG(uap, ctl)) { if (ctl.len != -1) if ((error = copyout(&sc, ctl.buf, ctl.len)) != 0) - return error; + goto out; if ((error = copyout(&ctl, SCARG(uap, ctl), sizeof(ctl))) != 0) - return error; + goto out; } if (SCARG(uap, dat)) { if ((error = copyout(&dat, SCARG(uap, dat), sizeof(dat))) != 0) - return error; + goto out; } if (SCARG(uap, flags)) { /* XXX: Need translation */ if ((error = copyout(&fl, SCARG(uap, flags), sizeof(fl))) != 0) - return error; + goto out; } *retval = 0; @@ -1860,5 +1881,7 @@ svr4_sys_getmsg(p, v, retval) show_msg("