Index: /issm/trunk-jpl/src/c/shared/Alloc/xNewDelete.h
===================================================================
--- /issm/trunk-jpl/src/c/shared/Alloc/xNewDelete.h	(revision 12447)
+++ /issm/trunk-jpl/src/c/shared/Alloc/xNewDelete.h	(revision 12448)
@@ -61,27 +61,33 @@
 T* xReNew(T* old, unsigned int old_size, unsigned int size) {
 #ifdef USE_CXX_MEMORY_MANAGMENT_FOR_NON_POD_TYPES
-  T* aT_p=NULL;
+  T* aT_p=0;
   if (!old) { // no old memory
     if (size)  
-      aT_p=xNew<T>(size);
+      aT_p=xNew<T>(size); // according to realloc behavior in manual page 
   }
   else { // have old memory
     if (!size)  // but 0 size
+      xDelete<T>(old); // according to realloc behavior in manual page
+    else { // non-zero size
+      assert(old_size); // have old memory - need to have old_size set or this call is bad
+      // allocate new, delete old; ; even for the case when size is 
+      // less than old_size we can't just keep the memory unchanged 
+      // because otherwise classes that have ctors/dtors with side-effects 
+      // may misbehave, for example classes with static instance/operations counters. 
+      aT_p=xNew<T>(size);
+      unsigned int iMax=(old_size<size)?old_size:size;
+      for (unsigned int i=0; i<iMax;++i) { 
+	// we need to copy the items by explicit assignments
+	aT_p[i]=old[i];
+      }
       xDelete<T>(old);
-    else { // non-zero size
-      if (size>old_size) { // do something only if it is bigger
-	aT_p=xNew<T>(size);
-	for (unsigned int i=0; i<old_size;++i) 
-	  aT_p[i]=old[i]; // copy the items
-	xDelete<T>(old);
-      }
-      else // size is equal or less than old size
-	aT_p=old; // do nothing
     }
   }
   return aT_p;
-#else 
-  T* aT_p=(T*)realloc((void*)old,size*sizeof(T));
-  assert(aT_p);
+#else
+  T* aT_p=0;
+  aT_p=(T*)realloc((void*)old,size*sizeof(T));
+  if (size) 
+    assert(aT_p); // according to realloc behavior in manual page
   return aT_p;
 #endif 
