On Thu, Jun 27, 2019 at 10:54:33AM +0100, Daniel P. Berrangé wrote:
The current VIR_AUTOPTR macro assumes that the struct needs to have a auto-free function auto-generated to call the real free function. The new VIR_AUTOSTRUCT macro allows for structs which already have a free function which takes a pointer to a pointer to the struct and can thus be used directly for auto-cleanup. Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- src/util/viralloc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index 2b82096fde..5de18b9ea0 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -614,3 +614,16 @@ void virAllocTestHook(void (*func)(int, void*), void *data); * when the variable goes out of scope. */ #define VIR_AUTOFREE(type) __attribute__((cleanup(virFree))) type + +/** + * VIR_AUTOSTRUCT: + * @type: type of the struct variable to be freed automatically + * + * Macro to automatically free the memory allocated to + * the struct variable declared with it by calling vir$STRUCTFree + * when the variable goes out of scope. + * + * The vir$STRUCTFree function must take a pointer to a pointer + * to the struct. + */ +#define VIR_AUTOSTRUCT(type) __attribute__((cleanup(type ## Free))) type
commit a4bfc2521f8aeff8f4e4431a8e2332cc74806b8a util: Move the VIR_AUTO(CLEAN|PTR) helper macros into a separate header moved the macros not depending on other stuff from viralloc.h to virautoclean.h This macro would better fit there. Also, sc_require_attribute_cleanup_initialization will need a touch-up. Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx> Jano
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list