Browse Source

HPCC-17745 JPtree memory usage greater than intended

Structure did not pack as intended.

Restore "Waiting for queries" logging line to its previous form, in case
external tools look for it.

Use correct check for little-endian - prior one did not work on Windows, and
would not have worked on big-endian machines.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 8 years ago
parent
commit
0f3507efd6
3 changed files with 24 additions and 28 deletions
  1. 2 1
      roxie/ccd/ccdmain.cpp
  2. 1 7
      system/jlib/jptree.cpp
  3. 21 20
      system/jlib/jptree.ipp

+ 2 - 1
roxie/ccd/ccdmain.cpp

@@ -1201,7 +1201,8 @@ int STARTQUERY_API start_query(int argc, const char *argv[])
                 roxieServer->start();
             }
             writeSentinelFile(sentinelFile);
-            DBGLOG("Waiting for queries LPT=%u APT=%u", queryNumLocalTrees(), queryNumAtomTrees());
+            DBGLOG("Startup completed - LPT=%u APT=%u", queryNumLocalTrees(), queryNumAtomTrees());
+            DBGLOG("Waiting for queries");
             if (pingInterval)
                 startPingTimer();
             LocalIAbortHandler abortHandler(waiter);

+ 1 - 7
system/jlib/jptree.cpp

@@ -27,12 +27,6 @@
 
 #include <algorithm>
 
-#if defined(_DEBUG) && defined(_WIN32) && !defined(USING_MPATROL)
- #undef new
- #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
-#endif
-
-
 #define MAKE_LSTRING(name,src,length) \
     const char *name = (const char *) alloca((length)+1); \
     memcpy((char *) name, (src), (length)); \
@@ -2986,7 +2980,7 @@ void LocalPTree::setAttribute(const char *key, const char *val)
     else
     {
         attrs = (AttrValue *)realloc(attrs, (numAttrs+1)*sizeof(AttrValue));
-        v = &attrs[numAttrs++];
+        v = new(&attrs[numAttrs++]) AttrValue;  // Initialize new AttrValue
         if (!v->key.set(key))
             v->key.setPtr(isnocase() ? AttrStr::createNC(key) : AttrStr::create(key));
     }

+ 21 - 20
system/jlib/jptree.ipp

@@ -380,33 +380,33 @@ struct PtrStrUnion
     union
     {
         PTR *ptr;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
         struct
         {
-#ifdef LITTLE_ENDIAN
             char flag;
-            union
-            {
-                char chars[sizeof(PTR *)-1];
-                struct
-                {
-                    int8_t idx1;
-                    int16_t idx2;
-                };
-            };
+            char chars[sizeof(PTR *)-1];
+        };
+        struct
+        {
+            char flagx;
+            int8_t idx1;
+            int16_t idx2;
+        };
 #else
-            union
-            {
-                char chars[sizeof(PTR *)-1];
-                struct
-                {
-                    int16_t idx2;
-                    int8_t idx1;
-                };
-            };
+        struct
+        {
+            char chars[sizeof(PTR *)-1];
             char flag;
-#endif
         };
+        struct
+        {
+            int16_t idx2;
+            int8_t idx1;
+            char flagx;
+        };
+#endif
     };
+
     inline PtrStrUnion<PTR>() : ptr(nullptr) {}
     inline bool isPtr() const
     {
@@ -487,6 +487,7 @@ struct PtrStrUnion
 #endif
 
 typedef PtrStrUnion<AttrStr> AttrStrUnion;
+static_assert(sizeof(AttrStrUnion) == sizeof(AttrStr *), "AttrStrUnion size mismatch");  // Sanity check!
 
 #ifdef USE_READONLY_ATOMTABLE
 struct AttrStrUnionWithTable : public AttrStrUnion