git: e2e956828caf - main - bhyve: return ENOMEM instead of EFAULT and call free() after being used
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 16 Jan 2024 14:40:41 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=e2e956828caf2f1db308d54b264c277c0abc25df
commit e2e956828caf2f1db308d54b264c277c0abc25df
Author: rilysh <nightquick@proton.me>
AuthorDate: 2024-01-08 06:06:55 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-01-16 14:39:25 +0000
bhyve: return ENOMEM instead of EFAULT and call free() after being used
1. In basl_load() function, when allocation fails,
it returns an EFAULT instead of ENOMEM. An EFAULT
can mislead in some scenarios, whereas an ENOMEM
for an allocation function makes much more sense.
2. Call free() on addr, as it's not being used
anymore after the basl_table_append_bytes()
function.
Signed-off-by: rilysh <nightquick@proton.me>
MFC after: 1 week
Pull Request: https://github.com/freebsd/freebsd-src/pull/1016
---
usr.sbin/bhyve/acpi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/usr.sbin/bhyve/acpi.c b/usr.sbin/bhyve/acpi.c
index b3d3c13fc946..85864da57af2 100644
--- a/usr.sbin/bhyve/acpi.c
+++ b/usr.sbin/bhyve/acpi.c
@@ -326,7 +326,7 @@ basl_load(struct vmctx *ctx, int fd)
addr = calloc(1, sb.st_size);
if (addr == NULL)
- return (EFAULT);
+ return (ENOMEM);
if (read(fd, addr, sb.st_size) < 0)
return (errno);
@@ -338,6 +338,7 @@ basl_load(struct vmctx *ctx, int fd)
BASL_EXEC(basl_table_create(&table, ctx, name, BASL_TABLE_ALIGNMENT));
BASL_EXEC(basl_table_append_bytes(table, addr, sb.st_size));
+ free(addr);
return (0);
}