libvmm: explicitly save and restore errno in vm_open()

In commit 6bb140e3ca, 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: 6bb140e3ca
This commit is contained in:
Robert Wing 2021-03-11 10:27:43 -09:00
parent b2ae176d91
commit a7f81b488d

View file

@ -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);
}