From owner-svn-src-all@freebsd.org Wed Oct 24 16:46:27 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 091BAFFC712; Wed, 24 Oct 2018 16:46:27 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AC3D16DB04; Wed, 24 Oct 2018 16:46:26 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 93D5D2CF8A; Wed, 24 Oct 2018 16:46:26 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9OGkQJJ071397; Wed, 24 Oct 2018 16:46:26 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9OGkQ6x071396; Wed, 24 Oct 2018 16:46:26 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201810241646.w9OGkQ6x071396@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Wed, 24 Oct 2018 16:46:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339687 - head/usr.sbin/rtsold X-SVN-Group: head X-SVN-Commit-Author: markj X-SVN-Commit-Paths: head/usr.sbin/rtsold X-SVN-Commit-Revision: 339687 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2018 16:46:27 -0000 Author: markj Date: Wed Oct 24 16:46:26 2018 New Revision: 339687 URL: https://svnweb.freebsd.org/changeset/base/339687 Log: Always free dynamically allocated memory before returning. CID: 1007418 MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Modified: head/usr.sbin/rtsold/rtsold.c Modified: head/usr.sbin/rtsold/rtsold.c ============================================================================== --- head/usr.sbin/rtsold/rtsold.c Wed Oct 24 16:41:47 2018 (r339686) +++ head/usr.sbin/rtsold/rtsold.c Wed Oct 24 16:46:26 2018 (r339687) @@ -334,16 +334,16 @@ ifconfig(char *ifname) struct sockaddr_dl *sdl; int flags; + ifi = NULL; if ((sdl = if_nametosdl(ifname)) == NULL) { warnmsg(LOG_ERR, __func__, "failed to get link layer information for %s", ifname); - return (-1); + goto bad; } if (find_ifinfo(sdl->sdl_index)) { warnmsg(LOG_ERR, __func__, "interface %s was already configured", ifname); - free(sdl); - return (-1); + goto bad; } if (Fflag) { @@ -352,30 +352,29 @@ ifconfig(char *ifname) if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { warnmsg(LOG_ERR, __func__, "socket() failed."); - return (-1); + goto bad; } memset(&nd, 0, sizeof(nd)); strlcpy(nd.ifname, ifname, sizeof(nd.ifname)); if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { warnmsg(LOG_ERR, __func__, "cannot get accept_rtadv flag"); - close(s); - return (-1); + (void)close(s); + goto bad; } nd.ndi.flags |= ND6_IFF_ACCEPT_RTADV; if (ioctl(s, SIOCSIFINFO_IN6, (caddr_t)&nd) < 0) { warnmsg(LOG_ERR, __func__, "cannot set accept_rtadv flag"); - close(s); - return (-1); + (void)close(s); + goto bad; } - close(s); + (void)close(s); } if ((ifi = malloc(sizeof(*ifi))) == NULL) { warnmsg(LOG_ERR, __func__, "memory allocation failed"); - free(sdl); - return (-1); + goto bad; } memset(ifi, 0, sizeof(*ifi)); ifi->sdl = sdl; @@ -426,7 +425,7 @@ ifconfig(char *ifname) return (0); bad: - free(ifi->sdl); + free(sdl); free(ifi); return (-1); }