If there are no hosts for a storage source virStorageSourceCopy would try to copy them anyways. As the success of virStorageNetHostDefCopy is determined by returning a pointer and malloc of 0 elements might return NULL according to the implementation, the result of the copy function may vary. Fix this by copying the hosts array only if there are hosts defined. --- src/util/virstoragefile.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 8e9d115..c2d5b46 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1852,9 +1852,12 @@ virStorageSourceCopy(const virStorageSource *src, VIR_STRDUP(ret->compat, src->compat) < 0) goto error; - if (!(ret->hosts = virStorageNetHostDefCopy(src->nhosts, src->hosts))) - goto error; - ret->nhosts = src->nhosts; + if (src->nhosts) { + if (!(ret->hosts = virStorageNetHostDefCopy(src->nhosts, src->hosts))) + goto error; + + ret->nhosts = src->nhosts; + } if (src->srcpool && !(ret->srcpool = virStorageSourcePoolDefCopy(src->srcpool))) -- 2.1.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list