aboutsummaryrefslogtreecommitdiff
path: root/include/qemu
diff options
context:
space:
mode:
authorVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>2021-06-28 15:11:32 +0300
committerKevin Wolf <kwolf@redhat.com>2021-06-29 16:51:21 +0200
commit4d324c0bf65c615ffbe95b35497353996b97753b (patch)
tree271f2cbf3892e8e42d67bcd67105431b9e9ce6bb /include/qemu
parent4c5393f169ca8587cc766928293bbcbbbdff78a4 (diff)
downloadqemu-4d324c0bf65c615ffbe95b35497353996b97753b.zip
qemu-4d324c0bf65c615ffbe95b35497353996b97753b.tar.gz
qemu-4d324c0bf65c615ffbe95b35497353996b97753b.tar.bz2
introduce QEMU_AUTO_VFREE
Introduce a convenient macro, that works for qemu_memalign() like g_autofree works with g_malloc. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20210628121133.193984-2-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'include/qemu')
-rw-r--r--include/qemu/osdep.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index c3656b7..c91a78b 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -387,6 +387,21 @@ void qemu_vfree(void *ptr);
void qemu_anon_ram_free(void *ptr, size_t size);
/*
+ * It's an analog of GLIB's g_autoptr_cleanup_generic_gfree(), used to define
+ * g_autofree macro.
+ */
+static inline void qemu_cleanup_generic_vfree(void *p)
+{
+ void **pp = (void **)p;
+ qemu_vfree(*pp);
+}
+
+/*
+ * Analog of g_autofree, but qemu_vfree is called on cleanup instead of g_free.
+ */
+#define QEMU_AUTO_VFREE __attribute__((cleanup(qemu_cleanup_generic_vfree)))
+
+/*
* Abstraction of PROT_ and MAP_ flags as passed to mmap(), for example,
* consumed by qemu_ram_mmap().
*/