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
This commit is contained in:
Daniel Veillard 2008-03-31 14:38:12 +00:00
parent be03daaab2
commit c7d7aa1cd1
5 changed files with 28 additions and 9 deletions

View File

@ -1,3 +1,9 @@
Mon Mar 31 16:35:47 CEST 2008 Daniel Veillard <veillard@redhat.com>
* 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 <veillard@redhat.com> Mon Mar 31 14:12:42 CEST 2008 Daniel Veillard <veillard@redhat.com>
* configure.in: small patch from Mike Gerdts to avoid problems with * configure.in: small patch from Mike Gerdts to avoid problems with

View File

@ -757,6 +757,9 @@ virReleaseConnect(virConnectPtr conn) {
virHashFree(conn->storageVols, (virHashDeallocator) virStorageVolFreeName); virHashFree(conn->storageVols, (virHashDeallocator) virStorageVolFreeName);
virResetError(&conn->err); virResetError(&conn->err);
if (__lastErr.conn == conn)
__lastErr.conn = NULL;
free(conn->name); free(conn->name);
pthread_mutex_unlock(&conn->lock); pthread_mutex_unlock(&conn->lock);
@ -880,6 +883,10 @@ virReleaseDomain(virDomainPtr domain) {
virHashError(conn, VIR_ERR_INTERNAL_ERROR, virHashError(conn, VIR_ERR_INTERNAL_ERROR,
_("domain missing from connection hash table")); _("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->magic = -1;
domain->id = -1; domain->id = -1;
free(domain->name); free(domain->name);
@ -1013,6 +1020,11 @@ virReleaseNetwork(virNetworkPtr network) {
virHashError(conn, VIR_ERR_INTERNAL_ERROR, virHashError(conn, VIR_ERR_INTERNAL_ERROR,
_("network missing from connection hash table")); _("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; network->magic = -1;
free(network->name); free(network->name);
free(network); free(network);

View File

@ -264,6 +264,7 @@ struct _virStorageVol {
* API for error handling * * API for error handling *
* * * *
************************************************************************/ ************************************************************************/
extern virError __lastErr;
void __virRaiseError(virConnectPtr conn, void __virRaiseError(virConnectPtr conn,
virDomainPtr dom, virDomainPtr dom,
virNetworkPtr net, virNetworkPtr net,

View File

@ -420,7 +420,7 @@ static void lxcFreeDriver(lxc_driver_t *driver)
static int lxcShutdown(void) static int lxcShutdown(void)
{ {
if (lxc_driver == NULL) if (lxc_driver == NULL)
return(NULL); return(-1);
lxcFreeVMs(lxc_driver->vms); lxcFreeVMs(lxc_driver->vms);
lxc_driver->vms = NULL; lxc_driver->vms = NULL;
lxcFreeDriver(lxc_driver); lxcFreeDriver(lxc_driver);

View File

@ -18,7 +18,7 @@
#include "libvirt/virterror.h" #include "libvirt/virterror.h"
#include "internal.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 }; { 0, 0, NULL, VIR_ERR_NONE, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL };
static virErrorFunc virErrorHandler = NULL; /* global error handler */ static virErrorFunc virErrorHandler = NULL; /* global error handler */
static void *virUserData = NULL; /* associated data */ static void *virUserData = NULL; /* associated data */
@ -72,9 +72,9 @@ static void *virUserData = NULL; /* associated data */
virErrorPtr virErrorPtr
virGetLastError(void) virGetLastError(void)
{ {
if (lastErr.code == VIR_ERR_OK) if (__lastErr.code == VIR_ERR_OK)
return (NULL); return (NULL);
return (&lastErr); return (&__lastErr);
} }
/* /*
@ -92,10 +92,10 @@ virCopyLastError(virErrorPtr to)
{ {
if (to == NULL) if (to == NULL)
return (-1); return (-1);
if (lastErr.code == VIR_ERR_OK) if (__lastErr.code == VIR_ERR_OK)
return (0); return (0);
memcpy(to, &lastErr, sizeof(virError)); memcpy(to, &__lastErr, sizeof(virError));
return (lastErr.code); return (__lastErr.code);
} }
/** /**
@ -124,7 +124,7 @@ virResetError(virErrorPtr err)
void void
virResetLastError(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, const char *str1, const char *str2, const char *str3,
int int1, int int2, const char *msg, ...) int int1, int int2, const char *msg, ...)
{ {
virErrorPtr to = &lastErr; virErrorPtr to = &__lastErr;
void *userData = virUserData; void *userData = virUserData;
virErrorFunc handler = virErrorHandler; virErrorFunc handler = virErrorHandler;
char *str; char *str;