[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libvir] [PATCH] deep copy dom structure



On Mon, Mar 31, 2008 at 08:12:19AM -0400, Daniel Veillard wrote:
> On Mon, Mar 31, 2008 at 01:02:49PM +0100, Daniel P. Berrange wrote:
> > We should at the very least NULL-ify the dom/net fields in the Error 
> > object associated with the Connection when we free the Domain/Network
> > object.
> 
>   agreed, very simple test but avoids dandling pointers.

  My patch for this. it's a bit more complex because we also keep a 
global variable for the last variable, and that needed to be exported to
the hash module, it's still rather simple,

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/
Index: src/hash.c
===================================================================
RCS file: /data/cvs/libxen/src/hash.c,v
retrieving revision 1.33
diff -p -r1.33 hash.c
*** src/hash.c	20 Feb 2008 15:06:53 -0000	1.33
--- src/hash.c	31 Mar 2008 12:46:28 -0000
*************** virReleaseConnect(virConnectPtr conn) {
*** 757,762 ****
--- 757,765 ----
          virHashFree(conn->storageVols, (virHashDeallocator) virStorageVolFreeName);
  
      virResetError(&conn->err);
+     if (__lastErr.conn == conn)
+         __lastErr.conn = NULL;
+ 
      free(conn->name);
  
      pthread_mutex_unlock(&conn->lock);
*************** virReleaseDomain(virDomainPtr domain) {
*** 880,885 ****
--- 883,892 ----
          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);
*************** virReleaseNetwork(virNetworkPtr network)
*** 1013,1018 ****
--- 1020,1030 ----
          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);
Index: src/internal.h
===================================================================
RCS file: /data/cvs/libxen/src/internal.h,v
retrieving revision 1.64
diff -p -r1.64 internal.h
*** src/internal.h	27 Feb 2008 16:14:44 -0000	1.64
--- src/internal.h	31 Mar 2008 12:46:28 -0000
*************** struct _virStorageVol {
*** 264,269 ****
--- 264,270 ----
   *		API for error handling					*
   *									*
   ************************************************************************/
+ extern virError __lastErr;
  void __virRaiseError(virConnectPtr conn,
  		     virDomainPtr dom,
  		     virNetworkPtr net,
Index: src/virterror.c
===================================================================
RCS file: /data/cvs/libxen/src/virterror.c,v
retrieving revision 1.40
diff -p -r1.40 virterror.c
*** src/virterror.c	21 Mar 2008 15:03:37 -0000	1.40
--- src/virterror.c	31 Mar 2008 12:46:28 -0000
***************
*** 18,24 ****
  #include "libvirt/virterror.h"
  #include "internal.h"
  
! static 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 */
--- 18,24 ----
  #include "libvirt/virterror.h"
  #include "internal.h"
  
! 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 */
*************** static void *virUserData = NULL;        
*** 72,80 ****
  virErrorPtr
  virGetLastError(void)
  {
!     if (lastErr.code == VIR_ERR_OK)
          return (NULL);
!     return (&lastErr);
  }
  
  /*
--- 72,80 ----
  virErrorPtr
  virGetLastError(void)
  {
!     if (__lastErr.code == VIR_ERR_OK)
          return (NULL);
!     return (&__lastErr);
  }
  
  /*
*************** virCopyLastError(virErrorPtr to)
*** 92,101 ****
  {
      if (to == NULL)
          return (-1);
!     if (lastErr.code == VIR_ERR_OK)
          return (0);
!     memcpy(to, &lastErr, sizeof(virError));
!     return (lastErr.code);
  }
  
  /**
--- 92,101 ----
  {
      if (to == NULL)
          return (-1);
!     if (__lastErr.code == VIR_ERR_OK)
          return (0);
!     memcpy(to, &__lastErr, sizeof(virError));
!     return (__lastErr.code);
  }
  
  /**
*************** virResetError(virErrorPtr err)
*** 124,130 ****
  void
  virResetLastError(void)
  {
!     virResetError(&lastErr);
  }
  
  /**
--- 124,130 ----
  void
  virResetLastError(void)
  {
!     virResetError(&__lastErr);
  }
  
  /**
*************** __virRaiseError(virConnectPtr conn, virD
*** 347,353 ****
                  const char *str1, const char *str2, const char *str3,
                  int int1, int int2, const char *msg, ...)
  {
!     virErrorPtr to = &lastErr;
      void *userData = virUserData;
      virErrorFunc handler = virErrorHandler;
      char *str;
--- 347,353 ----
                  const char *str1, const char *str2, const char *str3,
                  int int1, int int2, const char *msg, ...)
  {
!     virErrorPtr to = &__lastErr;
      void *userData = virUserData;
      virErrorFunc handler = virErrorHandler;
      char *str;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]