Displaying 1 result from an estimated 1 matches for "guestfs___defer_free".
2013 Jan 24
2
[PATCH 1/2] lib: Add CLEANUP_FREE macro which automatically calls 'free' when leaving scope.
...b/src/alloc.c
index 25d7f42..cf3741a 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -122,3 +122,22 @@ guestfs___safe_asprintf (guestfs_h *g, const char *fs, ...)
return msg;
}
+
+void
+guestfs___cleanup_free (void *ptr)
+{
+ free (* (void **) ptr);
+}
+
+#ifndef HAVE_ATTRIBUTE_CLEANUP
+void
+guestfs___defer_free (guestfs_h *g, void (*freefn) (void *), void *data)
+{
+ struct deferred_free *p = safe_malloc (g, sizeof *p);
+
+ p->freefn = freefn;
+ p->data = data;
+ p->next = g->deferred_frees;
+ g->deferred_frees = p;
+}
+#endif
diff --git a/src/guestfs-internal.h b/src/guestfs-internal....