diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1b02c25bb2..b681dc3464 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6015,7 +6015,8 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps, return obj; error: - virDomainObjUnref(obj); + /* obj was never shared, so unref should return 0 */ + ignore_value(virDomainObjUnref(obj)); return NULL; } @@ -8220,8 +8221,9 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps, return obj; error: + /* obj was never shared, so unref should return 0 */ if (obj) - virDomainObjUnref(obj); + ignore_value(virDomainObjUnref(obj)); VIR_FREE(statusFile); return NULL; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 9f595d6d9c..1e8223f5d9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1206,7 +1206,7 @@ int virDomainDeviceInfoIterate(virDomainDefPtr def, void virDomainDefFree(virDomainDefPtr vm); void virDomainObjRef(virDomainObjPtr vm); /* Returns 1 if the object was freed, 0 if more refs exist */ -int virDomainObjUnref(virDomainObjPtr vm); +int virDomainObjUnref(virDomainObjPtr vm) ATTRIBUTE_RETURN_CHECK; /* live == true means def describes an active domain (being migrated or * restored) as opposed to a new persistent configuration of the domain */ diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 0eb5ab3075..2fcca68cae 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -1,7 +1,7 @@ /* * openvz_conf.c: config functions for managing OpenVZ VEs * - * Copyright (C) 2010 Red Hat, Inc. + * Copyright (C) 2010-2011 Red Hat, Inc. * Copyright (C) 2006, 2007 Binary Karma * Copyright (C) 2006 Shuveb Hussain * Copyright (C) 2007 Anoop Joe Cyriac @@ -52,6 +52,7 @@ #include "nodeinfo.h" #include "files.h" #include "command.h" +#include "ignore-value.h" #define VIR_FROM_THIS VIR_FROM_OPENVZ @@ -543,8 +544,9 @@ int openvzLoadDomains(struct openvz_driver *driver) { cleanup: virCommandFree(cmd); VIR_FREE(outbuf); + /* dom hasn't been shared yet, so unref should return 0 */ if (dom) - virDomainObjUnref(dom); + ignore_value(virDomainObjUnref(dom)); return -1; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index cc137d2b58..c2a1f9a0ad 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -31,6 +31,7 @@ #include "c-ctype.h" #include "event.h" #include "cpu/cpu.h" +#include "ignore-value.h" #include @@ -460,7 +461,8 @@ int qemuDomainObjBeginJob(virDomainObjPtr obj) while (priv->jobActive) { if (virCondWaitUntil(&priv->jobCond, &obj->lock, then) < 0) { - virDomainObjUnref(obj); + /* Safe to ignore value since ref count was incremented above */ + ignore_value(virDomainObjUnref(obj)); if (errno == ETIMEDOUT) qemuReportError(VIR_ERR_OPERATION_TIMEOUT, "%s", _("cannot acquire state change lock")); @@ -504,7 +506,8 @@ int qemuDomainObjBeginJobWithDriver(struct qemud_driver *driver, while (priv->jobActive) { if (virCondWaitUntil(&priv->jobCond, &obj->lock, then) < 0) { - virDomainObjUnref(obj); + /* Safe to ignore value since ref count was incremented above */ + ignore_value(virDomainObjUnref(obj)); if (errno == ETIMEDOUT) qemuReportError(VIR_ERR_OPERATION_TIMEOUT, "%s", _("cannot acquire state change lock")); @@ -650,7 +653,9 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver, { qemuDriverLock(driver); virDomainObjLock(obj); - virDomainObjUnref(obj); + /* Safe to ignore value, since we incremented ref in + * qemuDomainObjEnterRemoteWithDriver */ + ignore_value(virDomainObjUnref(obj)); } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 4ccadcef29..800f7444bf 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -763,7 +763,7 @@ int qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon, if ((mon)->cb && (mon)->cb->callback) \ (ret) = ((mon)->cb->callback)(mon, __VA_ARGS__); \ qemuMonitorLock(mon); \ - qemuMonitorUnref(mon); \ + ignore_value(qemuMonitorUnref(mon)); \ } while (0) int qemuMonitorGetDiskSecret(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 1566a6d268..c90219b675 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -133,7 +133,7 @@ void qemuMonitorLock(qemuMonitorPtr mon); void qemuMonitorUnlock(qemuMonitorPtr mon); int qemuMonitorRef(qemuMonitorPtr mon); -int qemuMonitorUnref(qemuMonitorPtr mon); +int qemuMonitorUnref(qemuMonitorPtr mon) ATTRIBUTE_RETURN_CHECK; /* These APIs are for use by the internal Text/JSON monitor impl code only */ int qemuMonitorSend(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7831c3b3bf..76cceadc01 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -643,8 +643,9 @@ qemuConnectMonitor(struct qemud_driver *driver, virDomainObjPtr vm) priv->monJSON, &monitorCallbacks); + /* Safe to ignore value since ref count was incremented above */ if (priv->mon == NULL) - virDomainObjUnref(vm); + ignore_value(virDomainObjUnref(vm)); if (virSecurityManagerClearSocketLabel(driver->securityManager, vm) < 0) { VIR_ERROR(_("Failed to clear security context for monitor for %s"), diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index c3f53ea976..6339248a9e 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -1,5 +1,7 @@ /*---------------------------------------------------------------------------*/ -/* Copyright 2010, diateam (www.diateam.net) +/* + * Copyright (C) 2011 Red Hat, Inc. + * Copyright 2010, diateam (www.diateam.net) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -201,8 +203,9 @@ cleanup: VIR_FREE(directoryName); VIR_FREE(fileName); VIR_FREE(vmx); + /* any non-NULL vm here has not been shared, so unref will return 0 */ if (vm) - virDomainObjUnref(vm); + ignore_value(virDomainObjUnref(vm)); return ret; }