vbox: Adjust the UTF FREE macros

Adjust the macros to free memory allocated during various calls to
perform the check if parameter is NULL prior to really freeing and to
set the pointer to NULL after done freeing.
This commit is contained in:
John Ferlan 2013-01-23 19:34:48 -05:00 committed by Eric Blake
parent 4f01d3d53b
commit 97278ab472
2 changed files with 41 additions and 40 deletions

3
cfg.mk
View File

@ -93,6 +93,9 @@ VC_LIST_ALWAYS_EXCLUDE_REGEX = \
# Functions like free() that are no-ops on NULL arguments.
useless_free_options = \
--name=VBOX_UTF16_FREE \
--name=VBOX_UTF8_FREE \
--name=VBOX_COM_UNALLOC_MEM \
--name=VIR_FREE \
--name=qemuCapsFree \
--name=qemuMigrationCookieFree \

View File

@ -8,7 +8,7 @@
*/
/*
* Copyright (C) 2010-2012 Red Hat, Inc.
* Copyright (C) 2010-2013 Red Hat, Inc.
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
*
* This file is part of a free software library; you can redistribute
@ -80,9 +80,30 @@
#define VIR_FROM_THIS VIR_FROM_VBOX
#define VBOX_UTF16_FREE(arg) data->pFuncs->pfnUtf16Free(arg)
#define VBOX_UTF8_FREE(arg) data->pFuncs->pfnUtf8Free(arg)
#define VBOX_COM_UNALLOC_MEM(arg) data->pFuncs->pfnComUnallocMem(arg)
#define VBOX_UTF16_FREE(arg) \
do { \
if (arg) { \
data->pFuncs->pfnUtf16Free(arg); \
(arg) = NULL; \
} \
} while (0)
#define VBOX_UTF8_FREE(arg) \
do { \
if (arg) { \
data->pFuncs->pfnUtf8Free(arg); \
(arg) = NULL; \
} \
} while (0)
#define VBOX_COM_UNALLOC_MEM(arg) \
do { \
if (arg) { \
data->pFuncs->pfnComUnallocMem(arg); \
(arg) = NULL; \
} \
} while (0)
#define VBOX_UTF16_TO_UTF8(arg1, arg2) data->pFuncs->pfnUtf16ToUtf8(arg1, arg2)
#define VBOX_UTF8_TO_UTF16(arg1, arg2) data->pFuncs->pfnUtf8ToUtf16(arg1, arg2)
@ -1401,14 +1422,8 @@ static virDomainPtr vboxDomainLookupByName(virConnectPtr conn, const char *name)
ret->id = i + 1;
}
if (machineNameUtf8) {
VBOX_UTF8_FREE(machineNameUtf8);
machineNameUtf8 = NULL;
}
if (machineNameUtf16) {
VBOX_COM_UNALLOC_MEM(machineNameUtf16);
machineNameUtf16 = NULL;
}
if (matched == 1)
break;
}
@ -1971,9 +1986,7 @@ static int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) {
ret = 0;
}
if (machineName)
VBOX_UTF8_FREE(machineName);
if (machineNameUtf16)
VBOX_COM_UNALLOC_MEM(machineNameUtf16);
if (info->nrVirtCpu)
break;
@ -2435,10 +2448,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
VBOX_UTF16_TO_UTF8(valueDisplayUtf16, &valueDisplayUtf8);
VBOX_UTF16_FREE(valueDisplayUtf16);
if (strlen(valueDisplayUtf8) <= 0) {
if (strlen(valueDisplayUtf8) <= 0)
VBOX_UTF8_FREE(valueDisplayUtf8);
valueDisplayUtf8 = NULL;
}
}
if (STREQ(valueTypeUtf8, "sdl")) {
@ -2468,7 +2479,6 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) {
}
totalPresent++;
}
if (valueDisplayUtf8)
VBOX_UTF8_FREE(valueDisplayUtf8);
}
@ -3562,10 +3572,8 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine,
VBOX_UTF16_TO_UTF8(valueDisplayUtf16, &valueDisplayUtf8);
VBOX_UTF16_FREE(valueDisplayUtf16);
if (strlen(valueDisplayUtf8) <= 0) {
if (strlen(valueDisplayUtf8) <= 0)
VBOX_UTF8_FREE(valueDisplayUtf8);
valueDisplayUtf8 = NULL;
}
}
if (STREQ(valueTypeUtf8, "sdl")) {
@ -3613,7 +3621,6 @@ vboxStartMachine(virDomainPtr dom, int i, IMachine *machine,
} else {
guiPresent = 1;
}
if (valueDisplayUtf8)
VBOX_UTF8_FREE(valueDisplayUtf8);
if (guiPresent) {
@ -4592,10 +4599,7 @@ vboxAttachSerial(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
}
VBOX_RELEASE(serialPort);
if (pathUtf16) {
VBOX_UTF16_FREE(pathUtf16);
pathUtf16 = NULL;
}
}
}
}
@ -4659,10 +4663,7 @@ vboxAttachParallel(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
parallelPort->vtbl->SetEnabled(parallelPort, 1);
VBOX_RELEASE(parallelPort);
if (pathUtf16) {
VBOX_UTF16_FREE(pathUtf16);
pathUtf16 = NULL;
}
}
}
}
@ -8459,7 +8460,6 @@ static virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const
break;
}
if (nameUtf8)
VBOX_UTF8_FREE(nameUtf8);
}
}
@ -8591,7 +8591,6 @@ static virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const cha
vboxIIDUnalloc(&hddIID);
}
if (hddNameUtf8)
VBOX_UTF8_FREE(hddNameUtf8);
}
@ -8832,7 +8831,6 @@ static int vboxStorageVolDelete(virStorageVolPtr vol,
VIR_DEBUG("deregistering hdd:%d", deregister);
}
if (controller)
VBOX_UTF16_FREE(controller);
}
vboxIIDUnalloc(&iid);