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

[Xen-devel] [PATCH RFC v1 69/74] libxl_bitmap_copy_alloc: copy 0, NULL as 0, NULL



From: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>

We shouldn't allocate when it's both unnecessary, and not in
accordance with the thing we're copying.

One effect is to make a copied libxl__domain_build_info more like the
original, which is going to be helpful for the pv shim mode.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl_utils.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c
index 507ee56c7c..63b1a2cac1 100644
--- a/tools/libxl/libxl_utils.c
+++ b/tools/libxl/libxl_utils.c
@@ -659,9 +659,13 @@ void libxl_bitmap_copy_alloc(libxl_ctx *ctx,
 {
     GC_INIT(ctx);
 
-    dptr->map = libxl__calloc(NOGC, sptr->size, sizeof(*sptr->map));
     dptr->size = sptr->size;
-    memcpy(dptr->map, sptr->map, sptr->size * sizeof(*sptr->map));
+    if (sptr->map) {
+        dptr->map = libxl__calloc(NOGC, sptr->size, sizeof(*sptr->map));
+        memcpy(dptr->map, sptr->map, sptr->size * sizeof(*sptr->map));
+    } else {
+        dptr->map = NULL;
+    }
 
     GC_FREE;
 }
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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