[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Fix memory leak in xc_domain_dumpcore and simplify copy_from_domain_page.



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 47c562fd342a578fe62d784fbd955e82e2947264
# Parent  065006aa5322947f50a405b6504dff43a0ef6b15
Fix memory leak in xc_domain_dumpcore and simplify copy_from_domain_page.

Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>

diff -r 065006aa5322 -r 47c562fd342a tools/libxc/xc_core.c
--- a/tools/libxc/xc_core.c     Tue Mar 14 14:26:54 2006
+++ b/tools/libxc/xc_core.c     Tue Mar 14 14:33:57 2006
@@ -12,12 +12,11 @@
 static int
 copy_from_domain_page(int xc_handle,
                       uint32_t domid,
-                      unsigned long *page_array,
-                      unsigned long src_pfn,
+                      unsigned long mfn,
                       void *dst_page)
 {
     void *vaddr = xc_map_foreign_range(
-        xc_handle, domid, PAGE_SIZE, PROT_READ, page_array[src_pfn]);
+        xc_handle, domid, PAGE_SIZE, PROT_READ, mfn);
     if ( vaddr == NULL )
         return -1;
     memcpy(dst_page, vaddr, PAGE_SIZE);
@@ -32,7 +31,7 @@
                                 dumpcore_rtn_t dump_rtn)
 {
     unsigned long nr_pages;
-    unsigned long *page_array;
+    unsigned long *page_array = NULL;
     xc_dominfo_t info;
     int i, nr_vcpus = 0;
     char *dump_mem, *dump_mem_start = NULL;
@@ -79,11 +78,11 @@
     
     sts = dump_rtn(args, (char *)&header, sizeof(struct xc_core_header));
     if ( sts != 0 )
-        return sts;
+        goto error_out;
 
     sts = dump_rtn(args, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
     if ( sts != 0 )
-        return sts;
+        goto error_out;
 
     if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
     {
@@ -97,17 +96,17 @@
     }
     sts = dump_rtn(args, (char *)page_array, nr_pages * sizeof(unsigned long));
     if ( sts != 0 )
-        return sts;
+        goto error_out;
 
     /* Pad the output data to page alignment. */
     memset(dummy, 0, PAGE_SIZE);
     sts = dump_rtn(args, dummy, header.xch_pages_offset - dummy_len);
     if ( sts != 0 )
-        return sts;
+        goto error_out;
 
     for ( dump_mem = dump_mem_start, i = 0; i < nr_pages; i++ )
     {
-        copy_from_domain_page(xc_handle, domid, page_array, i, dump_mem);
+        copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem);
         dump_mem += PAGE_SIZE;
         if ( ((i + 1) % DUMP_INCREMENT == 0) || ((i + 1) == nr_pages) )
         {
@@ -119,10 +118,12 @@
     }
 
     free(dump_mem_start);
+    free(page_array);
     return 0;
 
  error_out:
     free(dump_mem_start);
+    free(page_array);
     return -1;
 }
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.