/* TODO check the UUID */
if (ret == NULL) {
if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
ret->name = strdup(name);
if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->domains, name, ret) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("failed to add domain to connection hash table"));
goto error;
return(ret);
error:
- virMutexUnlock(&conn->lock);
if (ret != NULL) {
VIR_FREE(ret->name);
VIR_FREE(ret);
DEBUG("release domain %p %s", domain, domain->name);
/* TODO search by UUID first as they are better differenciators */
- if (virHashRemoveEntry(conn->domains, domain->name, NULL) < 0)
+ if (virHashRemoveEntry(conn->domains, domain->name, NULL) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("domain missing from connection hash table"));
+ conn = NULL;
+ }
domain->magic = -1;
domain->id = -1;
VIR_FREE(domain->name);
VIR_FREE(domain);
- DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
+ if (conn) {
+ DEBUG("unref connection %p %d", conn, conn->refs);
+ conn->refs--;
+ if (conn->refs == 0) {
+ virReleaseConnect(conn);
+ /* Already unlocked mutex */
+ return;
+ }
+ virMutexUnlock(&conn->lock);
}
-
- virMutexUnlock(&conn->lock);
}
/* TODO check the UUID */
if (ret == NULL) {
if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
ret->name = strdup(name);
if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->networks, name, ret) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("failed to add network to connection hash table"));
goto error;
return(ret);
error:
- virMutexUnlock(&conn->lock);
if (ret != NULL) {
VIR_FREE(ret->name);
VIR_FREE(ret);
DEBUG("release network %p %s", network, network->name);
/* TODO search by UUID first as they are better differenciators */
- if (virHashRemoveEntry(conn->networks, network->name, NULL) < 0)
+ if (virHashRemoveEntry(conn->networks, network->name, NULL) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("network missing from connection hash table"));
+ conn = NULL;
+ }
network->magic = -1;
VIR_FREE(network->name);
VIR_FREE(network);
- DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
+ if (conn) {
+ DEBUG("unref connection %p %d", conn, conn->refs);
+ conn->refs--;
+ if (conn->refs == 0) {
+ virReleaseConnect(conn);
+ /* Already unlocked mutex */
+ return;
+ }
+ virMutexUnlock(&conn->lock);
}
-
- virMutexUnlock(&conn->lock);
}
/* TODO check the UUID */
if (ret == NULL) {
if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
ret->name = strdup(name);
if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
if (virHashAddEntry(conn->storagePools, name, ret) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("failed to add storage pool to connection hash table"));
goto error;
return(ret);
error:
- virMutexUnlock(&conn->lock);
if (ret != NULL) {
VIR_FREE(ret->name);
VIR_FREE(ret);
DEBUG("release pool %p %s", pool, pool->name);
/* TODO search by UUID first as they are better differenciators */
- if (virHashRemoveEntry(conn->storagePools, pool->name, NULL) < 0)
+ if (virHashRemoveEntry(conn->storagePools, pool->name, NULL) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("pool missing from connection hash table"));
+ conn = NULL;
+ }
pool->magic = -1;
VIR_FREE(pool->name);
VIR_FREE(pool);
- DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
+ if (conn) {
+ DEBUG("unref connection %p %d", conn, conn->refs);
+ conn->refs--;
+ if (conn->refs == 0) {
+ virReleaseConnect(conn);
+ /* Already unlocked mutex */
+ return;
+ }
+ virMutexUnlock(&conn->lock);
}
-
- virMutexUnlock(&conn->lock);
}
ret = (virStorageVolPtr) virHashLookup(conn->storageVols, key);
if (ret == NULL) {
if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
ret->pool = strdup(pool);
if (ret->pool == NULL) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
ret->name = strdup(name);
if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
ret->conn = conn;
if (virHashAddEntry(conn->storageVols, key, ret) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("failed to add storage vol to connection hash table"));
goto error;
return(ret);
error:
- virMutexUnlock(&conn->lock);
if (ret != NULL) {
VIR_FREE(ret->name);
VIR_FREE(ret->pool);
DEBUG("release vol %p %s", vol, vol->name);
/* TODO search by UUID first as they are better differenciators */
- if (virHashRemoveEntry(conn->storageVols, vol->key, NULL) < 0)
+ if (virHashRemoveEntry(conn->storageVols, vol->key, NULL) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("vol missing from connection hash table"));
+ conn = NULL;
+ }
vol->magic = -1;
VIR_FREE(vol->name);
VIR_FREE(vol->pool);
VIR_FREE(vol);
- DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
+ if (conn) {
+ DEBUG("unref connection %p %d", conn, conn->refs);
+ conn->refs--;
+ if (conn->refs == 0) {
+ virReleaseConnect(conn);
+ /* Already unlocked mutex */
+ return;
+ }
+ virMutexUnlock(&conn->lock);
}
-
- virMutexUnlock(&conn->lock);
}
ret = (virNodeDevicePtr) virHashLookup(conn->nodeDevices, name);
if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
ret->conn = conn;
ret->name = strdup(name);
if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
virReportOOMError(conn);
goto error;
}
if (virHashAddEntry(conn->nodeDevices, name, ret) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("failed to add node dev to conn hash table"));
goto error;
return(ret);
error:
- virMutexUnlock(&conn->lock);
if (ret != NULL) {
VIR_FREE(ret->name);
VIR_FREE(ret);
virConnectPtr conn = dev->conn;
DEBUG("release dev %p %s", dev, dev->name);
- if (virHashRemoveEntry(conn->nodeDevices, dev->name, NULL) < 0)
+ if (virHashRemoveEntry(conn->nodeDevices, dev->name, NULL) < 0) {
+ virMutexUnlock(&conn->lock);
virLibConnError(conn, VIR_ERR_INTERNAL_ERROR,
_("dev missing from connection hash table"));
+ conn = NULL;
+ }
dev->magic = -1;
VIR_FREE(dev->name);
VIR_FREE(dev->parent);
VIR_FREE(dev);
- DEBUG("unref connection %p %d", conn, conn->refs);
- conn->refs--;
- if (conn->refs == 0) {
- virReleaseConnect(conn);
- /* Already unlocked mutex */
- return;
+ if (conn) {
+ DEBUG("unref connection %p %d", conn, conn->refs);
+ conn->refs--;
+ if (conn->refs == 0) {
+ virReleaseConnect(conn);
+ /* Already unlocked mutex */
+ return;
+ }
+ virMutexUnlock(&conn->lock);
}
-
- virMutexUnlock(&conn->lock);
}