Port https://github.com/dotnet/coreclr/pull/13148 to master (#14999)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Sun, 12 Nov 2017 20:01:31 +0000 (21:01 +0100)
committerJan Kotas <jkotas@microsoft.com>
Sun, 12 Nov 2017 20:01:31 +0000 (12:01 -0800)
src/ilasm/typar.hpp

index 143a4a2..146128e 100644 (file)
@@ -51,17 +51,27 @@ private:
 
 class TyParList {
 public:
-       TyParList(DWORD a, BinStr* b, LPCUTF8 n, TyParList* nx = NULL) 
+    TyParList(DWORD a, BinStr* b, LPCUTF8 n, TyParList* nx = NULL) 
     { 
         bound  = (b == NULL) ? new BinStr() : b;
         bound->appendInt32(0); // zero terminator
-               attrs = a; name = n; next = nx;
-       };
-       ~TyParList() 
-    { 
-        if(bound) delete bound;
-               if (next) delete next; 
-       };
+        attrs = a; name = n; next = nx;
+    };
+    ~TyParList() 
+    {         
+        if( bound) delete bound;
+
+        // To avoid excessive stack usage (especially in debug builds), we break the next chain
+        // and delete as we traverse the link list
+        TyParList *pCur = next;
+        while (pCur != NULL)
+        {
+            TyParList *pTmp = pCur->next;
+            pCur->next = NULL;
+            delete pCur;
+            pCur = pTmp;
+        }
+    };
     int Count()
     {
         TyParList* tp = this;
@@ -154,7 +164,7 @@ public:
     TyParList* Next() { return next; };
     BinStr* Bound() { return bound; };
 private:
-       BinStr* bound;
+    BinStr* bound;
     LPCUTF8 name;
     TyParList* next;
     DWORD   attrs;