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.
This commit is contained in:
Marcelo Araujo 2018-06-13 11:49:34 +00:00
parent f764243341
commit f2b5dc3aec
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=335050

View File

@ -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 <assert.h>
#include <err.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <pthread.h>
#include "mem.h"
@ -285,8 +286,11 @@ register_mem_int(struct mmio_rb_tree *rbt, struct mem_range *memp)
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_range *memp)
assert(perror == 0);
if (err)
free(mrp);
} else
err = ENOMEM;
}
return (err);
}