From owner-svn-src-head@freebsd.org Tue Aug 14 19:12:47 2018 Return-Path: Delivered-To: svn-src-head@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 C830710550A2; Tue, 14 Aug 2018 19:12:46 +0000 (UTC) (envelope-from dab@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 7D7E0830F8; Tue, 14 Aug 2018 19:12:46 +0000 (UTC) (envelope-from dab@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 5E94F1FBB7; Tue, 14 Aug 2018 19:12:46 +0000 (UTC) (envelope-from dab@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7EJCkU4074951; Tue, 14 Aug 2018 19:12:46 GMT (envelope-from dab@FreeBSD.org) Received: (from dab@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7EJCjB5074948; Tue, 14 Aug 2018 19:12:45 GMT (envelope-from dab@FreeBSD.org) Message-Id: <201808141912.w7EJCjB5074948@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dab set sender to dab@FreeBSD.org using -f From: David Bright Date: Tue, 14 Aug 2018 19:12:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r337812 - in head: sys/dev/netmap tests/sys/kqueue/libkqueue X-SVN-Group: head X-SVN-Commit-Author: dab X-SVN-Commit-Paths: in head: sys/dev/netmap tests/sys/kqueue/libkqueue X-SVN-Commit-Revision: 337812 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Aug 2018 19:12:47 -0000 Author: dab Date: Tue Aug 14 19:12:45 2018 New Revision: 337812 URL: https://svnweb.freebsd.org/changeset/base/337812 Log: Fix several memory leaks. The libkqueue tests have several places that leak memory by using an idiom like: puts(kevent_to_str(kevp)); Rework to save the pointer returned from kevent_to_str() and then free() it after it has been used. Reported by: asomers (pointer to Coverity), Coverity CID: 1296063, 1296064, 1296065, 1296066, 1296067, 1350287, 1394960 Sponsored by: Dell EMC Modified: head/sys/dev/netmap/netmap_freebsd.c head/tests/sys/kqueue/libkqueue/common.h head/tests/sys/kqueue/libkqueue/main.c head/tests/sys/kqueue/libkqueue/proc.c Modified: head/sys/dev/netmap/netmap_freebsd.c ============================================================================== --- head/sys/dev/netmap/netmap_freebsd.c Tue Aug 14 18:58:16 2018 (r337811) +++ head/sys/dev/netmap/netmap_freebsd.c Tue Aug 14 19:12:45 2018 (r337812) @@ -1498,7 +1498,7 @@ netmap_kqfilter(struct cdev *dev, struct knote *kn) kn->kn_fop = (ev == EVFILT_WRITE) ? &netmap_wfiltops : &netmap_rfiltops; kn->kn_hook = priv; - knlist_add(&si->si.si_note, kn, 1); + knlist_add(&si->si.si_note, kn, 0); // XXX unlock(priv) ND("register %p %s td %p priv %p kn %p np_nifp %p kn_fp/fpop %s", na, na->ifp->if_xname, curthread, priv, kn, Modified: head/tests/sys/kqueue/libkqueue/common.h ============================================================================== --- head/tests/sys/kqueue/libkqueue/common.h Tue Aug 14 18:58:16 2018 (r337811) +++ head/tests/sys/kqueue/libkqueue/common.h Tue Aug 14 19:12:45 2018 (r337812) @@ -43,7 +43,7 @@ extern char *cur_test_id; int vnode_fd; -extern const char * kevent_to_str(struct kevent *); +extern char * kevent_to_str(struct kevent *); struct kevent * kevent_get(int); struct kevent * kevent_get_timeout(int, int); Modified: head/tests/sys/kqueue/libkqueue/main.c ============================================================================== --- head/tests/sys/kqueue/libkqueue/main.c Tue Aug 14 18:58:16 2018 (r337811) +++ head/tests/sys/kqueue/libkqueue/main.c Tue Aug 14 19:12:45 2018 (r337812) @@ -41,13 +41,16 @@ test_no_kevents(void) int nfds; struct timespec timeo; struct kevent kev; + char *kev_str; puts("confirming that there are no events pending"); memset(&timeo, 0, sizeof(timeo)); nfds = kevent(kqfd, NULL, 0, &kev, 1, &timeo); if (nfds != 0) { puts("\nUnexpected event:"); - puts(kevent_to_str(&kev)); + kev_str = kevent_to_str(&kev); + puts(kev_str); + free(kev_str); errx(1, "%d event(s) pending, but none expected:", nfds); } } @@ -61,12 +64,15 @@ test_no_kevents_quietly(void) int nfds; struct timespec timeo; struct kevent kev; + char *kev_str; memset(&timeo, 0, sizeof(timeo)); nfds = kevent(kqfd, NULL, 0, &kev, 1, &timeo); if (nfds != 0) { puts("\nUnexpected event:"); - puts(kevent_to_str(&kev)); + kev_str = kevent_to_str(&kev); + puts(kev_str); + free(kev_str); errx(1, "%d event(s) pending, but none expected:", nfds); } } @@ -193,18 +199,20 @@ kevent_flags_dump(struct kevent *kev) } /* Copied from ../kevent.c kevent_dump() and improved */ -const char * +char * kevent_to_str(struct kevent *kev) { char buf[512]; + char *flags_str = kevent_flags_dump(kev); + char *fflags_str = kevent_fflags_dump(kev); snprintf(&buf[0], sizeof(buf), "[ident=%ju, filter=%d, %s, %s, data=%jd, udata=%p, " "ext=[%jx %jx %jx %jx]", (uintmax_t) kev->ident, kev->filter, - kevent_flags_dump(kev), - kevent_fflags_dump(kev), + flags_str, + fflags_str, (uintmax_t)kev->data, kev->udata, (uintmax_t)kev->ext[0], @@ -212,6 +220,9 @@ kevent_to_str(struct kevent *kev) (uintmax_t)kev->ext[2], (uintmax_t)kev->ext[3]); + free(flags_str); + free(fflags_str); + return (strdup(buf)); } Modified: head/tests/sys/kqueue/libkqueue/proc.c ============================================================================== --- head/tests/sys/kqueue/libkqueue/proc.c Tue Aug 14 18:58:16 2018 (r337811) +++ head/tests/sys/kqueue/libkqueue/proc.c Tue Aug 14 19:12:45 2018 (r337812) @@ -172,6 +172,7 @@ proc_track(int sleep_time) int gchild_note = 0; pid_t gchild_pid = -1; int done = 0; + char *kev_str; while (!done) { @@ -182,7 +183,9 @@ proc_track(int sleep_time) if (kevp == NULL) { done = 1; } else { - printf(" -- Received kevent: %s\n", kevent_to_str(kevp)); + kev_str = kevent_to_str(kevp); + printf(" -- Received kevent: %s\n", kev_str); + free(kev_str); if ((kevp->fflags & NOTE_CHILD) && (kevp->fflags & NOTE_EXIT)) { errx(1, "NOTE_CHILD and NOTE_EXIT in same kevent: %s", kevent_to_str(kevp));