[PATCH] samples/acrn: check posix_memalign() for any error
From: Liam R. Howlett (Google)
Date: Mon Oct 19 2026 - 23:29:59 EST
posix_memalign() returns zero or a positive error number and does not set
errno. The check for a negative return is incorrect and a failed
allocation goes on to copy the guest code through guest_memory unset.
Test for a non-zero return.
Fixes: 32118bdc9471 ("virt: acrn: Replace obsolete memalign() with posix_memalign()")
Signed-off-by: Liam R. Howlett (Google) <liam@xxxxxxxxxxxxx>
---
samples/acrn/vm-sample.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/samples/acrn/vm-sample.c b/samples/acrn/vm-sample.c
index c61e0f91456e0..0f98d2d75ae7c 100644
--- a/samples/acrn/vm-sample.c
+++ b/samples/acrn/vm-sample.c
@@ -54,7 +54,7 @@ int main(int argc, char **argv)
argv = argv;
ret = posix_memalign(&guest_memory, 4096, GUEST_MEMORY_SIZE);
- if (ret < 0) {
+ if (ret) {
printf("Not enough memory!\n");
return -1;
}
--
2.47.3