This does a shallow copy of all the bits, then strdups the two items that are actually allocated separately. --- src/conf/domain_conf.c | 24 ++++++++++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 27 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9bcd47b..629c0bf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2018,6 +2018,30 @@ virDomainDeviceInfoIsSet(virDomainDeviceInfoPtr info, unsigned int flags) return false; } +int +virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, + virDomainDeviceInfoPtr src) +{ + /* Assume that dst is already cleared */ + + /* first a shallow copy of *everything* */ + *dst = *src; + + /* then redo the two fields that are pointers */ + dst->alias = NULL; + dst->romfile = NULL; + + if (src->alias && !(dst->alias = strdup(src->alias))) { + virReportOOMError(); + return -1; + } + if (src->romfile && !(dst->romfile = strdup(src->romfile))) { + virReportOOMError(); + return -1; + } + return 0; +} + void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info) { VIR_FREE(info->alias); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 06bb96c..f6f4739 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1885,6 +1885,8 @@ virDomainDeviceDefPtr virDomainDeviceDefCopy(virCapsPtr caps, virDomainDeviceDefPtr src); int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr info, int type); +int virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst, + virDomainDeviceInfoPtr src); void virDomainDeviceInfoClear(virDomainDeviceInfoPtr info); void virDomainDefClearPCIAddresses(virDomainDefPtr def); void virDomainDefClearDeviceAliases(virDomainDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 50e2720..3bf1a08 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -328,6 +328,7 @@ virDomainDeviceAddressTypeToString; virDomainDeviceDefCopy; virDomainDeviceDefFree; virDomainDeviceDefParse; +virDomainDeviceInfoCopy; virDomainDeviceInfoIterate; virDomainDeviceTypeToString; virDomainDiskBusTypeToString; -- 1.7.11.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list