In preparation for making virDomainSnapshotDef a descendant of
virObject, it is time to fix all callers that allocate an object to
use virDomainSnapshotDefNew() instead of VIR_ALLOC(). Fortunately,
there aren't very many :)
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/conf/snapshot_conf.h | 1 +
src/conf/snapshot_conf.c | 16 +++++++++++++---
src/libvirt_private.syms | 1 +
src/vbox/vbox_common.c | 3 ++-
4 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h
index f54be11619..0ce9dda355 100644
--- a/src/conf/snapshot_conf.h
+++ b/src/conf/snapshot_conf.h
@@ -114,6 +114,7 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml,
virDomainXMLOptionPtr xmlopt,
bool *current,
unsigned int flags);
+virDomainSnapshotDefPtr virDomainSnapshotDefNew(void);
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
char *virDomainSnapshotDefFormat(const char *uuidstr,
virDomainSnapshotDefPtr def,
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index dd281d57fe..e5771ae635 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -81,7 +81,17 @@ virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk)
disk->src = NULL;
}
-void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
+virDomainSnapshotDefPtr
+virDomainSnapshotDefNew(void)
+{
+ virDomainSnapshotDefPtr def;
+
+ ignore_value(VIR_ALLOC(def));
+ return def;
+}
+
+void
+virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
{
size_t i;
@@ -205,8 +215,8 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
bool offline = !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE);
virSaveCookieCallbacksPtr saveCookie = virDomainXMLOptionGetSaveCookie(xmlopt);
- if (VIR_ALLOC(def) < 0)
- goto cleanup;
+ if (!(def = virDomainSnapshotDefNew()))
+ return NULL;
def->parent.name = virXPathString("string(./name)", ctxt);
if (def->parent.name == NULL) {
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a03cf0b645..0474a4e44c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -894,6 +894,7 @@ virDomainSnapshotAlignDisks;
virDomainSnapshotDefFormat;
virDomainSnapshotDefFree;
virDomainSnapshotDefIsExternal;
+virDomainSnapshotDefNew;
virDomainSnapshotDefParseString;
virDomainSnapshotFormatConvertXMLFlags;
virDomainSnapshotIsExternal;
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index af557690c4..7e42f6a4fe 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6220,7 +6220,8 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr
snapshot,
if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name)))
goto cleanup;
- if (VIR_ALLOC(def) < 0 || !(def->parent.dom = virDomainDefNew()))
+ if (!(def = virDomainSnapshotDefNew()) ||
+ !(def->parent.dom = virDomainDefNew()))
goto cleanup;
defdom = def->parent.dom;
if (VIR_STRDUP(def->parent.name, snapshot->name) < 0)
--
2.20.1