[libvirt] [PATCH 02/10] src: Use consistent error preservation and restoration calls

John Ferlan jferlan at redhat.com
Tue Oct 15 17:37:20 UTC 2019


Provide some consistency over error message variable name and usage
when saving error messages across possible other errors or possibility
of resetting of the last error.

Instead of virSaveLastError paired up with virSetError and virFreeError,
we should use the newer virErrorPreserveLast and virRestoreError.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/libvirt-stream.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c
index ef83696bcd..fb646d0aef 100644
--- a/src/libvirt-stream.c
+++ b/src/libvirt-stream.c
@@ -622,12 +622,11 @@ virStreamSendAll(virStreamPtr stream,
     VIR_FREE(bytes);
 
     if (ret != 0) {
-        virErrorPtr orig_err = virSaveLastError();
+        virErrorPtr orig_err;
+
+        virErrorPreserveLast(&orig_err);
         virStreamAbort(stream);
-        if (orig_err) {
-            virSetError(orig_err);
-            virFreeError(orig_err);
-        }
+        virErrorRestore(&orig_err);
         virDispatchError(stream->conn);
     }
 
@@ -794,12 +793,11 @@ int virStreamSparseSendAll(virStreamPtr stream,
     VIR_FREE(bytes);
 
     if (ret != 0) {
-        virErrorPtr orig_err = virSaveLastError();
+        virErrorPtr orig_err;
+
+        virErrorPreserveLast(&orig_err);
         virStreamAbort(stream);
-        if (orig_err) {
-            virSetError(orig_err);
-            virFreeError(orig_err);
-        }
+        virErrorRestore(&orig_err);
         virDispatchError(stream->conn);
     }
 
@@ -900,12 +898,11 @@ virStreamRecvAll(virStreamPtr stream,
     VIR_FREE(bytes);
 
     if (ret != 0) {
-        virErrorPtr orig_err = virSaveLastError();
+        virErrorPtr orig_err;
+
+        virErrorPreserveLast(&orig_err);
         virStreamAbort(stream);
-        if (orig_err) {
-            virSetError(orig_err);
-            virFreeError(orig_err);
-        }
+        virErrorRestore(&orig_err);
         virDispatchError(stream->conn);
     }
 
@@ -1034,12 +1031,11 @@ virStreamSparseRecvAll(virStreamPtr stream,
     VIR_FREE(bytes);
 
     if (ret != 0) {
-        virErrorPtr orig_err = virSaveLastError();
+        virErrorPtr orig_err;
+
+        virErrorPreserveLast(&orig_err);
         virStreamAbort(stream);
-        if (orig_err) {
-            virSetError(orig_err);
-            virFreeError(orig_err);
-        }
+        virErrorRestore(&orig_err);
         virDispatchError(stream->conn);
     }
 
-- 
2.20.1




More information about the libvir-list mailing list