From c7d7aa1cd17c606ae02648d36e74fd8b29b5bf85 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Mon, 31 Mar 2008 14:38:12 +0000 Subject: [PATCH] remove dandling domain/net/conn pointers from error data * src/hash.c src/internal.h src/virterror.c: remove dandling domain/net/conn pointers from error data when released. * src/lxc_driver.c: fix a NULL/0 return error mismatch Daniel --- ChangeLog | 6 ++++++ src/hash.c | 12 ++++++++++++ src/internal.h | 1 + src/lxc_driver.c | 2 +- src/virterror.c | 16 ++++++++-------- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4acfaec512..dbc39172cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Mar 31 16:35:47 CEST 2008 Daniel Veillard + + * src/hash.c src/internal.h src/virterror.c: remove dandling + domain/net/conn pointers from error data when released. + * src/lxc_driver.c: fix a NULL/0 return error mismatch + Mon Mar 31 14:12:42 CEST 2008 Daniel Veillard * configure.in: small patch from Mike Gerdts to avoid problems with diff --git a/src/hash.c b/src/hash.c index 45d743370d..99177bcf12 100644 --- a/src/hash.c +++ b/src/hash.c @@ -757,6 +757,9 @@ virReleaseConnect(virConnectPtr conn) { virHashFree(conn->storageVols, (virHashDeallocator) virStorageVolFreeName); virResetError(&conn->err); + if (__lastErr.conn == conn) + __lastErr.conn = NULL; + free(conn->name); pthread_mutex_unlock(&conn->lock); @@ -880,6 +883,10 @@ virReleaseDomain(virDomainPtr domain) { virHashError(conn, VIR_ERR_INTERNAL_ERROR, _("domain missing from connection hash table")); + if (conn->err.dom == domain) + conn->err.dom = NULL; + if (__lastErr.dom == domain) + __lastErr.dom = NULL; domain->magic = -1; domain->id = -1; free(domain->name); @@ -1013,6 +1020,11 @@ virReleaseNetwork(virNetworkPtr network) { virHashError(conn, VIR_ERR_INTERNAL_ERROR, _("network missing from connection hash table")); + if (conn->err.net == network) + conn->err.net = NULL; + if (__lastErr.net == network) + __lastErr.net = NULL; + network->magic = -1; free(network->name); free(network); diff --git a/src/internal.h b/src/internal.h index d3a566459a..dde673b00f 100644 --- a/src/internal.h +++ b/src/internal.h @@ -264,6 +264,7 @@ struct _virStorageVol { * API for error handling * * * ************************************************************************/ +extern virError __lastErr; void __virRaiseError(virConnectPtr conn, virDomainPtr dom, virNetworkPtr net, diff --git a/src/lxc_driver.c b/src/lxc_driver.c index a9afae6a5b..a4e77859fa 100644 --- a/src/lxc_driver.c +++ b/src/lxc_driver.c @@ -420,7 +420,7 @@ static void lxcFreeDriver(lxc_driver_t *driver) static int lxcShutdown(void) { if (lxc_driver == NULL) - return(NULL); + return(-1); lxcFreeVMs(lxc_driver->vms); lxc_driver->vms = NULL; lxcFreeDriver(lxc_driver); diff --git a/src/virterror.c b/src/virterror.c index 1e39be40a4..92ccf67d93 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -18,7 +18,7 @@ #include "libvirt/virterror.h" #include "internal.h" -static virError lastErr = /* the last error */ +virError __lastErr = /* the last error */ { 0, 0, NULL, VIR_ERR_NONE, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL }; static virErrorFunc virErrorHandler = NULL; /* global error handler */ static void *virUserData = NULL; /* associated data */ @@ -72,9 +72,9 @@ static void *virUserData = NULL; /* associated data */ virErrorPtr virGetLastError(void) { - if (lastErr.code == VIR_ERR_OK) + if (__lastErr.code == VIR_ERR_OK) return (NULL); - return (&lastErr); + return (&__lastErr); } /* @@ -92,10 +92,10 @@ virCopyLastError(virErrorPtr to) { if (to == NULL) return (-1); - if (lastErr.code == VIR_ERR_OK) + if (__lastErr.code == VIR_ERR_OK) return (0); - memcpy(to, &lastErr, sizeof(virError)); - return (lastErr.code); + memcpy(to, &__lastErr, sizeof(virError)); + return (__lastErr.code); } /** @@ -124,7 +124,7 @@ virResetError(virErrorPtr err) void virResetLastError(void) { - virResetError(&lastErr); + virResetError(&__lastErr); } /** @@ -347,7 +347,7 @@ __virRaiseError(virConnectPtr conn, virDomainPtr dom, virNetworkPtr net, const char *str1, const char *str2, const char *str3, int int1, int int2, const char *msg, ...) { - virErrorPtr to = &lastErr; + virErrorPtr to = &__lastErr; void *userData = virUserData; virErrorFunc handler = virErrorHandler; char *str; -- GitLab