From fa7f51b813518bc305a1d4231495940654570b5c Mon Sep 17 00:00:00 2001 From: John Levon Date: Mon, 9 Feb 2009 14:16:23 +0000 Subject: introduce virSaveLastError(), virFreeError() --- src/virterror.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/virterror.c') diff --git a/src/virterror.c b/src/virterror.c index 6c479f43d..42a7cf578 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -285,6 +285,27 @@ virCopyLastError(virErrorPtr to) return to->code; } +/** + * virSaveLastError: + * + * Save the last error into a new error object. + * + * Returns a pointer to the copied error or NULL if allocation failed. + * It is the caller's responsibility to free the error with + * virFreeError(). + */ +virErrorPtr +virSaveLastError(void) +{ + virErrorPtr to; + + if (VIR_ALLOC(to) < 0) + return NULL; + + virCopyLastError(to); + return to; +} + /** * virResetError: * @err: pointer to the virError to clean up @@ -303,6 +324,18 @@ virResetError(virErrorPtr err) memset(err, 0, sizeof(virError)); } +/** + * virFreeError: + * @err: error to free + * + * Resets and frees the given error. + */ +void +virFreeError(virErrorPtr err) +{ + virResetError(err); + VIR_FREE(err); +} /** * virResetLastError: -- cgit v1.2.3-65-gdbad