#### vmopen.c:
```
#include <dlfcn.h>
#include <err.h>
#include <vmmapi.h>
int main(int argc, char *argv[])
{
const char *vmname = argc > 1 ? argv[1] : "-";
struct vmctx *ctx;
void (*__vm_close)(struct vmctx *ctx) = dlsym(RTLD_NEXT, "vm_close");
ctx = vm_open(vmname);
if (ctx == NULL)
err(1, "cannot open vm device: %s", vmname);
if (__vm_close)
__vm_close(ctx);
}
```
---
#### Compile:
```$ cc -W -Wall -Wextra vmopen.c -l dl -lvmmapi```
#### Create "testvm" env:
```$ sysctl hw.vmm.create=testvm```
#### Run with original libvmmapi.so:
```
$ valgrind ./vmopen testvm
...
==95593== HEAP SUMMARY:
==95593== in use at exit: 55 bytes in 1 blocks
==95593== total heap usage: 2 allocs, 1 frees, 71 bytes allocated
==95593==
==95593== LEAK SUMMARY:
==95593== definitely lost: 55 bytes in 1 blocks
```
#### Run with libvmmapi.so has vm_close()
```
LD_PRELOAD=/data/lib/libvmmapi.so valgrind ./vmopen testvm
==95674== HEAP SUMMARY:
==95674== in use at exit: 0 bytes in 0 blocks
==95674== total heap usage: 2 allocs, 2 frees, 71 bytes allocated
==95674==
==95674== All heap blocks were freed -- no leaks are possible
```