From a7f81b488df2d4a5dcd785b4112e04ffb6ca0442 Mon Sep 17 00:00:00 2001 From: Robert Wing Date: Thu, 11 Mar 2021 10:27:43 -0900 Subject: [PATCH] libvmm: explicitly save and restore errno in vm_open() In commit 6bb140e3ca895a14, vm_destroy() was replaced with free() to preserve errno. However, it's possible that free() may change the errno as well. Keep the free() call, but explicitly save and restore errno. Noted by: jhb Fixes: 6bb140e3ca895a14 --- lib/libvmmapi/vmmapi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c index 7faa2fc545ea..5810274c9a73 100644 --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -118,6 +118,7 @@ struct vmctx * vm_open(const char *name) { struct vmctx *vm; + int saved_errno; vm = malloc(sizeof(struct vmctx) + strlen(name) + 1); assert(vm != NULL); @@ -133,7 +134,9 @@ vm_open(const char *name) return (vm); err: + saved_errno = errno; free(vm); + errno = saved_errno; return (NULL); }