http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1699

*** shadow/1699 Thu May 10 05:48:21 2001
--- shadow/1699.tmp.18227       Thu May 10 05:48:21 2001
***************
*** 0 ****
--- 1,80 ----
+ +============================================================================+
+ | Memory leak in DOMSring class                                              |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 1699                        Product: Xerces-C                |
+ |       Status: NEW                         Version: 1.4                     |
+ |   Resolution:                            Platform: Other                   |
+ |     Severity: Major                    OS/Version: AIX                     |
+ |     Priority: Medium                    Component: DOM                     |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: [EMAIL PROTECTED]                                  |
+ |  Reported By: [EMAIL PROTECTED]                                 |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ Platform: IBM
+ OS: AIX4.3
+ Compiler: xlC_r version 5
+ 
+ There is a bug in xlC_r related to the overloading of the delete operator on a 
+ class when the code is compiled with optimization flags (-O or -O2).
+ 
+ sample code
+ ---------------------------------------------------------------
+ #include <stdlib.h>
+ #include <stdio.h>
+ 
+ class Toto
+ {
+ public:
+         Toto() {printf("Constructor\n");}
+         ~Toto() {printf("Destructor\n");}
+ 
+         void *operator new(size_t t)
+         {
+                 printf("operator new\n");
+                 return malloc(t);
+         }
+ 
+         void operator delete(void *ptr)
+         {
+                 printf("operator delete\n");
+                 free(ptr);
+         }
+ 
+         void close1()
+         { delete this; }// OK without optim flags
+                         // NOK with -O or -O2 (calls the destructor only)
+ 
+         void close2()
+         { Toto *ptr = this;
+           delete ptr; } // OK in all cases
+ };
+ 
+ int main(int argc, char *argv[])
+ {
+         printf("\nDIRECT DELETE\n");
+         Toto *a = new Toto;
+         delete a;       // OK - calls the destructor, then the delete operator
+ 
+         printf("\nDELEGATED DELETE - 1\n");
+         a = new Toto;
+         a->close1();
+ 
+         printf("\nDELEGATED DELETE - 2\n");
+         a = new Toto;
+         a->close2();
+ 
+      return 0;
+ }
+ 
+ The DOMStringHandle class overloads the new and delete operator. And 
+ since -O is a default compilation flags in release mode, it ends
+ up as a memory leak each time DOMString instances are created !
+ 
+ Workaround:
+ -----------
+ You can either use the close2() method suggested in the sample code, or
+ remove -O as a default compilation flag on AIX.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to