diff --git a/src/internal.h b/src/internal.h index cf03a82105..5a868bb00c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -279,6 +279,21 @@ (b) = NULL; \ } while (0) +/** + * VIR_RETURN_PTR: + * @ret: pointer to return + * + * Returns value of @ret while clearing @ret. This ensures that pointers + * freed by using VIR_AUTOPTR can be easily passed back to the caller without + * any temporary variable. @ptr is evaluated more than once. + */ +# define VIR_RETURN_PTR(ptr) \ + do { \ + typeof(ptr) virTemporaryReturnPointer = (ptr); \ + (ptr) = NULL; \ + return virTemporaryReturnPointer; \ + } while (0) + /** * virCheckFlags: * @supported: an OR'ed set of supported flags