snapshot: Add virDomainSnapshotDefNew

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@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Eric Blake 2019-05-08 13:30:38 -05:00
parent 098043eddd
commit 7fe07761a7
4 changed files with 15 additions and 3 deletions

View File

@ -81,6 +81,15 @@ virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk)
disk->src = NULL; disk->src = NULL;
} }
virDomainSnapshotDefPtr
virDomainSnapshotDefNew(void)
{
virDomainSnapshotDefPtr def;
ignore_value(VIR_ALLOC(def));
return def;
}
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def) void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
{ {
size_t i; size_t i;
@ -205,8 +214,8 @@ virDomainSnapshotDefParse(xmlXPathContextPtr ctxt,
bool offline = !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE); bool offline = !!(flags & VIR_DOMAIN_SNAPSHOT_PARSE_OFFLINE);
virSaveCookieCallbacksPtr saveCookie = virDomainXMLOptionGetSaveCookie(xmlopt); virSaveCookieCallbacksPtr saveCookie = virDomainXMLOptionGetSaveCookie(xmlopt);
if (VIR_ALLOC(def) < 0) if (!(def = virDomainSnapshotDefNew()))
goto cleanup; return NULL;
def->parent.name = virXPathString("string(./name)", ctxt); def->parent.name = virXPathString("string(./name)", ctxt);
if (def->parent.name == NULL) { if (def->parent.name == NULL) {

View File

@ -114,6 +114,7 @@ virDomainSnapshotDefPtr virDomainSnapshotDefParseNode(xmlDocPtr xml,
virDomainXMLOptionPtr xmlopt, virDomainXMLOptionPtr xmlopt,
bool *current, bool *current,
unsigned int flags); unsigned int flags);
virDomainSnapshotDefPtr virDomainSnapshotDefNew(void);
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def); void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def);
char *virDomainSnapshotDefFormat(const char *uuidstr, char *virDomainSnapshotDefFormat(const char *uuidstr,
virDomainSnapshotDefPtr def, virDomainSnapshotDefPtr def,

View File

@ -894,6 +894,7 @@ virDomainSnapshotAlignDisks;
virDomainSnapshotDefFormat; virDomainSnapshotDefFormat;
virDomainSnapshotDefFree; virDomainSnapshotDefFree;
virDomainSnapshotDefIsExternal; virDomainSnapshotDefIsExternal;
virDomainSnapshotDefNew;
virDomainSnapshotDefParseString; virDomainSnapshotDefParseString;
virDomainSnapshotFormatConvertXMLFlags; virDomainSnapshotFormatConvertXMLFlags;
virDomainSnapshotIsExternal; virDomainSnapshotIsExternal;

View File

@ -6220,7 +6220,8 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name))) if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name)))
goto cleanup; goto cleanup;
if (VIR_ALLOC(def) < 0 || !(def->parent.dom = virDomainDefNew())) if (!(def = virDomainSnapshotDefNew()) ||
!(def->parent.dom = virDomainDefNew()))
goto cleanup; goto cleanup;
defdom = def->parent.dom; defdom = def->parent.dom;
if (VIR_STRDUP(def->parent.name, snapshot->name) < 0) if (VIR_STRDUP(def->parent.name, snapshot->name) < 0)