85f7e77
diff --git a/Makefile.am b/Makefile.am
85f7e77
index 43c2710..c160a95 100644
85f7e77
--- a/Makefile.am
85f7e77
+++ b/Makefile.am
85f7e77
@@ -29,7 +29,8 @@ if LIBWRAP
85f7e77
 AM_CPPFLAGS +=	-DLIBWRAP
85f7e77
 endif
85f7e77
 
85f7e77
-bin_PROGRAMS = rpcbind rpcinfo
85f7e77
+bin_PROGRAMS = rpcinfo
85f7e77
+sbin_PROGRAMS = rpcbind
85f7e77
 
85f7e77
 rpcbind_SOURCES = \
85f7e77
 	src/check_bound.c \
85f7e77
diff --git a/configure.ac b/configure.ac
85f7e77
index 3790310..359a418 100644
85f7e77
--- a/configure.ac
85f7e77
+++ b/configure.ac
85f7e77
@@ -61,9 +61,9 @@ AC_SEARCH_LIBS([pthread_create], [pthread])
85f7e77
 
85f7e77
 AC_CHECK_HEADERS([nss.h rpcsvc/mount.h])
85f7e77
 
85f7e77
-# make bindir available for substitution in config file
85f7e77
+# make sbindir available for substitution in config file
85f7e77
 # 2 "evals" needed to expand variable names
85f7e77
-AC_SUBST([_bindir])
85f7e77
-AC_CONFIG_COMMANDS_PRE([eval eval _bindir=$bindir])
85f7e77
+AC_SUBST([_sbindir])
85f7e77
+AC_CONFIG_COMMANDS_PRE([eval eval _sbindir=$sbindir])
85f7e77
 
85f7e77
 AC_OUTPUT([Makefile systemd/rpcbind.service])
85f7e77
diff --git a/src/pmap_svc.c b/src/pmap_svc.c
85f7e77
index 4c744fe..a53dd5f 100644
85f7e77
--- a/src/pmap_svc.c
85f7e77
+++ b/src/pmap_svc.c
85f7e77
@@ -175,6 +175,7 @@ pmapproc_change(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt, unsigned long
85f7e77
 	long ans;
85f7e77
 	uid_t uid;
85f7e77
 	char uidbuf[32];
85f7e77
+	int rc = TRUE;
85f7e77
 
85f7e77
 	/*
85f7e77
 	 * Can't use getpwnam here. We might end up calling ourselves
85f7e77
@@ -194,7 +195,8 @@ pmapproc_change(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt, unsigned long
85f7e77
 
85f7e77
 	if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (char *)&reg)) {
85f7e77
 		svcerr_decode(xprt);
85f7e77
-		return (FALSE);
85f7e77
+		rc = FALSE;
85f7e77
+		goto done;
85f7e77
 	}
85f7e77
 #ifdef RPCBIND_DEBUG
85f7e77
 	if (debugging)
85f7e77
@@ -205,7 +207,8 @@ pmapproc_change(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt, unsigned long
85f7e77
 
85f7e77
 	if (!check_access(xprt, op, reg.pm_prog, PMAPVERS)) {
85f7e77
 		svcerr_weakauth(xprt);
85f7e77
-		return (FALSE);
85f7e77
+		rc = (FALSE);
85f7e77
+		goto done;
85f7e77
 	}
85f7e77
 
85f7e77
 	rpcbreg.r_prog = reg.pm_prog;
85f7e77
@@ -258,7 +261,18 @@ done_change:
85f7e77
 		rpcbs_set(RPCBVERS_2_STAT, ans);
85f7e77
 	else
85f7e77
 		rpcbs_unset(RPCBVERS_2_STAT, ans);
85f7e77
-	return (TRUE);
85f7e77
+done:
85f7e77
+	if (!svc_freeargs(xprt, (xdrproc_t) xdr_pmap, (char *)&reg)) {
85f7e77
+#ifdef RPCBIND_DEBUG
85f7e77
+		if (debugging) {
85f7e77
+			(void) xlog(LOG_DEBUG, "unable to free arguments\n");
85f7e77
+			if (doabort) {
85f7e77
+				rpcbind_abort();
85f7e77
+			}
85f7e77
+		}
85f7e77
+#endif
85f7e77
+	}
85f7e77
+	return (rc);
85f7e77
 }
85f7e77
 
85f7e77
 /* ARGSUSED */
85f7e77
@@ -272,15 +286,18 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
85f7e77
 #ifdef RPCBIND_DEBUG
85f7e77
 	char *uaddr;
85f7e77
 #endif
85f7e77
+	int rc = TRUE;
85f7e77
 
85f7e77
 	if (!svc_getargs(xprt, (xdrproc_t) xdr_pmap, (char *)&reg)) {
85f7e77
 		svcerr_decode(xprt);
85f7e77
-		return (FALSE);
85f7e77
+		rc = FALSE;
85f7e77
+		goto done;
85f7e77
 	}
85f7e77
 
85f7e77
 	if (!check_access(xprt, PMAPPROC_GETPORT, reg.pm_prog, PMAPVERS)) {
85f7e77
 		svcerr_weakauth(xprt);
85f7e77
-		return FALSE;
85f7e77
+		rc = FALSE;
85f7e77
+		goto done;
85f7e77
 	}
85f7e77
 
85f7e77
 #ifdef RPCBIND_DEBUG
85f7e77
@@ -330,21 +347,36 @@ pmapproc_getport(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
85f7e77
 		pmap_ipprot2netid(reg.pm_prot) ?: "<unknown>",
85f7e77
 		port ? udptrans : "");
85f7e77
 
85f7e77
-	return (TRUE);
85f7e77
+done:
85f7e77
+	if (!svc_freeargs(xprt, (xdrproc_t) xdr_pmap, (char *)&reg)) {
85f7e77
+#ifdef RPCBIND_DEBUG
85f7e77
+		if (debugging) {
85f7e77
+			(void) xlog(LOG_DEBUG, "unable to free arguments\n");
85f7e77
+			if (doabort) {
85f7e77
+				rpcbind_abort();
85f7e77
+			}
85f7e77
+		}
85f7e77
+#endif
85f7e77
+	}
85f7e77
+	return (rc);
85f7e77
 }
85f7e77
 
85f7e77
 /* ARGSUSED */
85f7e77
 static bool_t
85f7e77
 pmapproc_dump(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
85f7e77
 {
85f7e77
+	int rc = TRUE;
85f7e77
+
85f7e77
 	if (!svc_getargs(xprt, (xdrproc_t)xdr_void, NULL)) {
85f7e77
 		svcerr_decode(xprt);
85f7e77
-		return (FALSE);
85f7e77
+		rc = FALSE;
85f7e77
+		goto done;
85f7e77
 	}
85f7e77
 
85f7e77
 	if (!check_access(xprt, PMAPPROC_DUMP, 0, PMAPVERS)) {
85f7e77
 		svcerr_weakauth(xprt);
85f7e77
-		return FALSE;
85f7e77
+		rc = FALSE;
85f7e77
+		goto done;
85f7e77
 	}
85f7e77
 	
85f7e77
 	if ((!svc_sendreply(xprt, (xdrproc_t) xdr_pmaplist_ptr,
85f7e77
@@ -354,7 +386,19 @@ pmapproc_dump(struct svc_req *rqstp /*__unused*/, SVCXPRT *xprt)
85f7e77
 			rpcbind_abort();
85f7e77
 		}
85f7e77
 	}
85f7e77
-	return (TRUE);
85f7e77
+
85f7e77
+done:
85f7e77
+	if (!svc_freeargs(xprt, (xdrproc_t) xdr_void, (char *)NULL)) {
85f7e77
+#ifdef RPCBIND_DEBUG
85f7e77
+		if (debugging) {
85f7e77
+			(void) xlog(LOG_DEBUG, "unable to free arguments\n");
85f7e77
+			if (doabort) {
85f7e77
+				rpcbind_abort();
85f7e77
+			}
85f7e77
+		}
85f7e77
+#endif
85f7e77
+	}
85f7e77
+	return (rc);
85f7e77
 }
85f7e77
 
85f7e77
 int pmap_netid2ipprot(const char *netid)
85f7e77
diff --git a/src/rpcb_svc.c b/src/rpcb_svc.c
85f7e77
index 709e3fb..091f530 100644
85f7e77
--- a/src/rpcb_svc.c
85f7e77
+++ b/src/rpcb_svc.c
85f7e77
@@ -166,7 +166,7 @@ rpcb_service_3(struct svc_req *rqstp, SVCXPRT *transp)
85f7e77
 		svcerr_decode(transp);
85f7e77
 		if (debugging)
85f7e77
 			(void) xlog(LOG_DEBUG, "rpcbind: could not decode");
85f7e77
-		return;
85f7e77
+		goto done;
85f7e77
 	}
85f7e77
 
85f7e77
 	if (rqstp->rq_proc == RPCBPROC_SET
85f7e77
diff --git a/src/rpcb_svc_4.c b/src/rpcb_svc_4.c
85f7e77
index 5094879..eebbbbe 100644
85f7e77
--- a/src/rpcb_svc_4.c
85f7e77
+++ b/src/rpcb_svc_4.c
85f7e77
@@ -218,7 +218,7 @@ rpcb_service_4(struct svc_req *rqstp, SVCXPRT *transp)
85f7e77
 		svcerr_decode(transp);
85f7e77
 		if (debugging)
85f7e77
 			(void) xlog(LOG_DEBUG, "rpcbind: could not decode\n");
85f7e77
-		return;
85f7e77
+		goto done;
85f7e77
 	}
85f7e77
 
85f7e77
 	if (rqstp->rq_proc == RPCBPROC_SET
85f7e77
diff --git a/src/rpcb_svc_com.c b/src/rpcb_svc_com.c
85f7e77
index 5862c26..9c1c3af 100644
85f7e77
--- a/src/rpcb_svc_com.c
85f7e77
+++ b/src/rpcb_svc_com.c
85f7e77
@@ -612,9 +612,7 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
85f7e77
 	struct netconfig *nconf;
85f7e77
 	struct netbuf *caller;
85f7e77
 	struct r_rmtcall_args a;
85f7e77
-	char *buf_alloc = NULL, *outbufp;
85f7e77
-	char *outbuf_alloc = NULL;
85f7e77
-	char buf[RPC_BUF_MAX], outbuf[RPC_BUF_MAX];
85f7e77
+	char  outbuf[RPC_BUF_MAX];
85f7e77
 	struct netbuf *na = (struct netbuf *) NULL;
85f7e77
 	struct rpc_msg call_msg;
85f7e77
 	int outlen;
85f7e77
@@ -635,36 +633,10 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
85f7e77
 	}
85f7e77
 	if (si.si_socktype != SOCK_DGRAM)
85f7e77
 		return;	/* Only datagram type accepted */
85f7e77
-	sendsz = __rpc_get_t_size(si.si_af, si.si_proto, UDPMSGSIZE);
85f7e77
-	if (sendsz == 0) {	/* data transfer not supported */
85f7e77
-		if (reply_type == RPCBPROC_INDIRECT)
85f7e77
-			svcerr_systemerr(transp);
85f7e77
-		return;
85f7e77
-	}
85f7e77
-	/*
85f7e77
-	 * Should be multiple of 4 for XDR.
85f7e77
-	 */
85f7e77
-	sendsz = ((sendsz + 3) / 4) * 4;
85f7e77
-	if (sendsz > RPC_BUF_MAX) {
85f7e77
-#ifdef	notyet
85f7e77
-		buf_alloc = alloca(sendsz);		/* not in IDR2? */
85f7e77
-#else
85f7e77
-		buf_alloc = malloc(sendsz);
85f7e77
-#endif	/* notyet */
85f7e77
-		if (buf_alloc == NULL) {
85f7e77
-			if (debugging)
85f7e77
-				xlog(LOG_DEBUG,
85f7e77
-					"rpcbproc_callit_com:  No Memory!\n");
85f7e77
-			if (reply_type == RPCBPROC_INDIRECT)
85f7e77
-				svcerr_systemerr(transp);
85f7e77
-			return;
85f7e77
-		}
85f7e77
-		a.rmt_args.args = buf_alloc;
85f7e77
-	} else {
85f7e77
-		a.rmt_args.args = buf;
85f7e77
-	}
85f7e77
+	sendsz = UDPMSGSIZE;
85f7e77
 
85f7e77
 	call_msg.rm_xid = 0;	/* For error checking purposes */
85f7e77
+	memset(&a, 0, sizeof(a)); /* Zero out the input buffer */
85f7e77
 	if (!svc_getargs(transp, (xdrproc_t) xdr_rmtcall_args, (char *) &a)) {
85f7e77
 		if (reply_type == RPCBPROC_INDIRECT)
85f7e77
 			svcerr_decode(transp);
85f7e77
@@ -700,11 +672,11 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
85f7e77
 
85f7e77
 	rpcbs_rmtcall(versnum - 2, reply_type, a.rmt_prog, a.rmt_vers,
85f7e77
 			a.rmt_proc, transp->xp_netid, rbl);
85f7e77
-
85f7e77
 	if (rbl == (rpcblist_ptr)NULL) {
85f7e77
 #ifdef RPCBIND_DEBUG
85f7e77
 		if (debugging)
85f7e77
-			xlog(LOG_DEBUG, "not found\n");
85f7e77
+			xlog(LOG_DEBUG, "prog %lu vers %lu: not found\n", 
85f7e77
+				a.rmt_prog, a.rmt_vers);
85f7e77
 #endif
85f7e77
 		if (reply_type == RPCBPROC_INDIRECT)
85f7e77
 			svcerr_noprog(transp);
85f7e77
@@ -818,24 +790,10 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
85f7e77
 	call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
85f7e77
 	call_msg.rm_call.cb_prog = a.rmt_prog;
85f7e77
 	call_msg.rm_call.cb_vers = a.rmt_vers;
85f7e77
-	if (sendsz > RPC_BUF_MAX) {
85f7e77
-#ifdef	notyet
85f7e77
-		outbuf_alloc = alloca(sendsz);	/* not in IDR2? */
85f7e77
-#else
85f7e77
-		outbuf_alloc = malloc(sendsz);
85f7e77
-#endif	/* notyet */
85f7e77
-		if (outbuf_alloc == NULL) {
85f7e77
-			if (reply_type == RPCBPROC_INDIRECT)
85f7e77
-				svcerr_systemerr(transp);
85f7e77
-			if (debugging)
85f7e77
-				xlog(LOG_DEBUG,
85f7e77
-				"rpcbproc_callit_com:  No memory!\n");
85f7e77
-			goto error;
85f7e77
-		}
85f7e77
-		xdrmem_create(&outxdr, outbuf_alloc, sendsz, XDR_ENCODE);
85f7e77
-	} else {
85f7e77
-		xdrmem_create(&outxdr, outbuf, sendsz, XDR_ENCODE);
85f7e77
-	}
85f7e77
+
85f7e77
+	memset(outbuf, '\0', sendsz); /* Zero out the output buffer */
85f7e77
+	xdrmem_create(&outxdr, outbuf, sendsz, XDR_ENCODE);
85f7e77
+
85f7e77
 	if (!xdr_callhdr(&outxdr, &call_msg)) {
85f7e77
 		if (reply_type == RPCBPROC_INDIRECT)
85f7e77
 			svcerr_systemerr(transp);
85f7e77
@@ -900,10 +858,6 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
85f7e77
 		goto error;
85f7e77
 	}
85f7e77
 	outlen = (int) XDR_GETPOS(&outxdr);
85f7e77
-	if (outbuf_alloc)
85f7e77
-		outbufp = outbuf_alloc;
85f7e77
-	else
85f7e77
-		outbufp = outbuf;
85f7e77
 
85f7e77
 	na = uaddr2taddr(nconf, local_uaddr);
85f7e77
 	if (!na) {
85f7e77
@@ -912,7 +866,7 @@ rpcbproc_callit_com(struct svc_req *rqstp, SVCXPRT *transp,
85f7e77
 		goto error;
85f7e77
 	}
85f7e77
 
85f7e77
-	if (sendto(fd, outbufp, outlen, 0, (struct sockaddr *)na->buf, na->len)
85f7e77
+	if (sendto(fd, outbuf, outlen, 0, (struct sockaddr *)na->buf, na->len)
85f7e77
 	    != outlen) {
85f7e77
 		if (debugging)
85f7e77
 			xlog(LOG_DEBUG,
85f7e77
@@ -927,12 +881,16 @@ error:
85f7e77
 	if (call_msg.rm_xid != 0)
85f7e77
 		(void) free_slot_by_xid(call_msg.rm_xid);
85f7e77
 out:
85f7e77
+	if (!svc_freeargs(transp, (xdrproc_t) xdr_rmtcall_args, (char *) &a)) {
85f7e77
+		if (debugging) {
85f7e77
+			(void) xlog(LOG_DEBUG, "unable to free arguments\n");
85f7e77
+			if (doabort) {
85f7e77
+				rpcbind_abort();
85f7e77
+			}
85f7e77
+		}
85f7e77
+	}
85f7e77
 	if (local_uaddr)
85f7e77
 		free(local_uaddr);
85f7e77
-	if (buf_alloc)
85f7e77
-		free(buf_alloc);
85f7e77
-	if (outbuf_alloc)
85f7e77
-		free(outbuf_alloc);
85f7e77
 	if (na) {
85f7e77
 		free(na->buf);
85f7e77
 		free(na);
85f7e77
@@ -1094,7 +1052,6 @@ void
85f7e77
 my_svc_run()
85f7e77
 {
85f7e77
 	int poll_ret, check_ret;
85f7e77
-	int n;
85f7e77
 
85f7e77
 	for (;;) {
85f7e77
 	        struct pollfd my_pollfd[svc_max_pollfd];
85f7e77
diff --git a/systemd/rpcbind.service.in b/systemd/rpcbind.service.in
85f7e77
index e7e86da..7b1c74b 100644
85f7e77
--- a/systemd/rpcbind.service.in
85f7e77
+++ b/systemd/rpcbind.service.in
85f7e77
@@ -2,16 +2,17 @@
85f7e77
 Description=RPC Bind
85f7e77
 Documentation=man:rpcbind(8)
85f7e77
 DefaultDependencies=no
85f7e77
+RequiresMountsFor=@statedir@
85f7e77
 
85f7e77
 # Make sure we use the IP addresses listed for
85f7e77
 # rpcbind.socket, no matter how this unit is started.
85f7e77
-Wants=rpcbind.socket
85f7e77
-After=rpcbind.socket
85f7e77
+Requires=rpcbind.socket
85f7e77
+Wants=rpcbind.target
85f7e77
 
85f7e77
 [Service]
85f7e77
 Type=notify
85f7e77
 # distro can provide a drop-in adding EnvironmentFile=-/??? if needed.
85f7e77
-ExecStart=@_bindir@/rpcbind $RPCBIND_OPTIONS -w -f
85f7e77
+ExecStart=@_sbindir@/rpcbind $RPCBIND_OPTIONS -w -f
85f7e77
 
85f7e77
 [Install]
85f7e77
 WantedBy=multi-user.target