[Pkg-libvirt-commits] [libguestfs] 48/61: virt-diff: Free memory along error path.

Hilko Bengen bengen at moszumanska.debian.org
Sat Mar 29 14:36:31 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 7792278e0534e0e91ddc160aee46f1623a5769a1
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Mar 26 20:23:19 2014 +0000

    virt-diff: Free memory along error path.
    
    Found by Coverity.
---
 diff/diff.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/diff/diff.c b/diff/diff.c
index 3ba79eb..87d57d5 100644
--- a/diff/diff.c
+++ b/diff/diff.c
@@ -459,9 +459,9 @@ visit_entry (const char *dir, const char *name,
              void *vt)
 {
   struct tree *t = vt;
-  char *path, *csum = NULL;
-  struct guestfs_stat *stat;
-  struct guestfs_xattr_list *xattrs;
+  char *path = NULL, *csum = NULL;
+  struct guestfs_stat *stat = NULL;
+  struct guestfs_xattr_list *xattrs = NULL;
   size_t i;
 
   path = full_path (dir, name);
@@ -472,18 +472,18 @@ visit_entry (const char *dir, const char *name,
   stat = guestfs_copy_stat (stat_orig);
   if (stat == NULL) {
     perror ("guestfs_copy_stat");
-    return -1;
+    goto error;
   }
   xattrs = guestfs_copy_xattr_list (xattrs_orig);
   if (xattrs == NULL) {
     perror ("guestfs_copy_xattr_list");
-    return -1;
+    goto error;
   }
 
   if (checksum && is_reg (stat->mode)) {
     csum = guestfs_checksum (t->g, checksum, path);
     if (!csum)
-      return -1;
+      goto error;
   }
 
   /* If --atime option was NOT passed, flatten the atime field. */
@@ -521,7 +521,7 @@ visit_entry (const char *dir, const char *name,
       perror ("realloc");
       t->files = old_files;
       t->allocated = old_allocated;
-      return -1;
+      goto error;
     }
   }
 
@@ -531,6 +531,13 @@ visit_entry (const char *dir, const char *name,
   t->files[i].csum = csum;
 
   return 0;
+
+ error:
+  free (path);
+  free (csum);
+  guestfs_free_stat (stat);
+  guestfs_free_xattr_list (xattrs);
+  return -1;
 }
 
 static void deleted (guestfs_h *, struct file *);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list