From owner-svn-src-head@freebsd.org Wed Jun 13 11:49:35 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 0799D10016D5; Wed, 13 Jun 2018 11:49:35 +0000 (UTC) (envelope-from araujo@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 B16707D362; Wed, 13 Jun 2018 11:49:34 +0000 (UTC) (envelope-from araujo@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 9376218F95; Wed, 13 Jun 2018 11:49:34 +0000 (UTC) (envelope-from araujo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5DBnYZ5082279; Wed, 13 Jun 2018 11:49:34 GMT (envelope-from araujo@FreeBSD.org) Received: (from araujo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5DBnYE2082278; Wed, 13 Jun 2018 11:49:34 GMT (envelope-from araujo@FreeBSD.org) Message-Id: <201806131149.w5DBnYE2082278@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: araujo set sender to araujo@FreeBSD.org using -f From: Marcelo Araujo Date: Wed, 13 Jun 2018 11:49:34 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335050 - head/usr.sbin/bhyve X-SVN-Group: head X-SVN-Commit-Author: araujo X-SVN-Commit-Paths: head/usr.sbin/bhyve X-SVN-Commit-Revision: 335050 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.26 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: Wed, 13 Jun 2018 11:49:35 -0000 Author: araujo Date: Wed Jun 13 11:49:34 2018 New Revision: 335050 URL: https://svnweb.freebsd.org/changeset/base/335050 Log: While I was investigating CID 1194192 related with a resource leak on mrp memory allocation, I could identify that actually we use this pointer on pci_emul.c as well as on vga.c source file. I have reworked the logic here to make it more readable and also add a warn to explicit show the function where the memory allocation error could happen, also sort headers. Also CID 1194192 was marked as "Intentional". Obtained from: TrueOS MFC after: 4 weeks. Sponsored by: iXsystems Inc. Modified: head/usr.sbin/bhyve/mem.c Modified: head/usr.sbin/bhyve/mem.c ============================================================================== --- head/usr.sbin/bhyve/mem.c Wed Jun 13 11:12:52 2018 (r335049) +++ head/usr.sbin/bhyve/mem.c Wed Jun 13 11:49:34 2018 (r335050) @@ -38,15 +38,16 @@ __FBSDID("$FreeBSD$"); #include -#include #include +#include #include #include -#include -#include #include +#include #include +#include +#include #include "mem.h" @@ -285,8 +286,11 @@ register_mem_int(struct mmio_rb_tree *rbt, struct mem_ err = 0; mrp = malloc(sizeof(struct mmio_rb_range)); - - if (mrp != NULL) { + if (mrp == NULL) { + warn("%s: couldn't allocate memory for mrp\n", + __func__); + err = ENOMEM; + } else { mrp->mr_param = *memp; mrp->mr_base = memp->base; mrp->mr_end = memp->base + memp->size - 1; @@ -297,8 +301,7 @@ register_mem_int(struct mmio_rb_tree *rbt, struct mem_ assert(perror == 0); if (err) free(mrp); - } else - err = ENOMEM; + } return (err); }