ia64/xen-unstable

changeset 9253:47c562fd342a

Fix memory leak in xc_domain_dumpcore and simplify copy_from_domain_page.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Mar 14 15:33:57 2006 +0100 (2006-03-14)
parents 065006aa5322
children 14bfb2eb9505
files tools/libxc/xc_core.c
line diff
     1.1 --- a/tools/libxc/xc_core.c	Tue Mar 14 15:26:54 2006 +0100
     1.2 +++ b/tools/libxc/xc_core.c	Tue Mar 14 15:33:57 2006 +0100
     1.3 @@ -12,12 +12,11 @@
     1.4  static int
     1.5  copy_from_domain_page(int xc_handle,
     1.6                        uint32_t domid,
     1.7 -                      unsigned long *page_array,
     1.8 -                      unsigned long src_pfn,
     1.9 +                      unsigned long mfn,
    1.10                        void *dst_page)
    1.11  {
    1.12      void *vaddr = xc_map_foreign_range(
    1.13 -        xc_handle, domid, PAGE_SIZE, PROT_READ, page_array[src_pfn]);
    1.14 +        xc_handle, domid, PAGE_SIZE, PROT_READ, mfn);
    1.15      if ( vaddr == NULL )
    1.16          return -1;
    1.17      memcpy(dst_page, vaddr, PAGE_SIZE);
    1.18 @@ -32,7 +31,7 @@ xc_domain_dumpcore_via_callback(int xc_h
    1.19                                  dumpcore_rtn_t dump_rtn)
    1.20  {
    1.21      unsigned long nr_pages;
    1.22 -    unsigned long *page_array;
    1.23 +    unsigned long *page_array = NULL;
    1.24      xc_dominfo_t info;
    1.25      int i, nr_vcpus = 0;
    1.26      char *dump_mem, *dump_mem_start = NULL;
    1.27 @@ -79,11 +78,11 @@ xc_domain_dumpcore_via_callback(int xc_h
    1.28      
    1.29      sts = dump_rtn(args, (char *)&header, sizeof(struct xc_core_header));
    1.30      if ( sts != 0 )
    1.31 -        return sts;
    1.32 +        goto error_out;
    1.33  
    1.34      sts = dump_rtn(args, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
    1.35      if ( sts != 0 )
    1.36 -        return sts;
    1.37 +        goto error_out;
    1.38  
    1.39      if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
    1.40      {
    1.41 @@ -97,17 +96,17 @@ xc_domain_dumpcore_via_callback(int xc_h
    1.42      }
    1.43      sts = dump_rtn(args, (char *)page_array, nr_pages * sizeof(unsigned long));
    1.44      if ( sts != 0 )
    1.45 -        return sts;
    1.46 +        goto error_out;
    1.47  
    1.48      /* Pad the output data to page alignment. */
    1.49      memset(dummy, 0, PAGE_SIZE);
    1.50      sts = dump_rtn(args, dummy, header.xch_pages_offset - dummy_len);
    1.51      if ( sts != 0 )
    1.52 -        return sts;
    1.53 +        goto error_out;
    1.54  
    1.55      for ( dump_mem = dump_mem_start, i = 0; i < nr_pages; i++ )
    1.56      {
    1.57 -        copy_from_domain_page(xc_handle, domid, page_array, i, dump_mem);
    1.58 +        copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem);
    1.59          dump_mem += PAGE_SIZE;
    1.60          if ( ((i + 1) % DUMP_INCREMENT == 0) || ((i + 1) == nr_pages) )
    1.61          {
    1.62 @@ -119,10 +118,12 @@ xc_domain_dumpcore_via_callback(int xc_h
    1.63      }
    1.64  
    1.65      free(dump_mem_start);
    1.66 +    free(page_array);
    1.67      return 0;
    1.68  
    1.69   error_out:
    1.70      free(dump_mem_start);
    1.71 +    free(page_array);
    1.72      return -1;
    1.73  }
    1.74