Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Jun 2018 11:49:34 +0000 (UTC)
From:      Marcelo Araujo <araujo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335050 - head/usr.sbin/bhyve
Message-ID:  <201806131149.w5DBnYE2082278@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/types.h>
-#include <sys/tree.h>
 #include <sys/errno.h>
+#include <sys/tree.h>
 #include <machine/vmm.h>
 #include <machine/vmm_instruction_emul.h>
 
-#include <stdio.h>
-#include <stdlib.h>
 #include <assert.h>
+#include <err.h>
 #include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
 
 #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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806131149.w5DBnYE2082278>