[Issue 11777] [ICE] dmd memory corruption as `Scope::pop` `free`s `fieldinit` used also in `enclosing`

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 24 15:21:38 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11777



--- Comment #7 from Kenji Hara <k.hara.pg at gmail.com> 2013-12-24 15:21:31 PST ---
(In reply to comment #6)
> So now everyone can add `assert(enclosing->fieldinit != fieldinit);` check in
> `Scope::pop` and test if the issue is triggered in his codebase, as in the
> worst case it may silently occur without visible effect but with code
> corruption.

Denis, can you test this patch?

 src/scope.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/scope.c b/src/scope.c
index f51a30c..c22b585 100644
--- a/src/scope.c
+++ b/src/scope.c
@@ -188,14 +188,17 @@ Scope *Scope::pop()
         enclosing->callSuper |= callSuper;
         if (enclosing->fieldinit && fieldinit)
         {
+            assert(enclosing->fieldinit != fieldinit);
+
             size_t dim = fieldinit_dim;
             for (size_t i = 0; i < dim; i++)
                 enclosing->fieldinit[i] |= fieldinit[i];
-            /* Workaround regression @@@BUG11777@@@.
-            Probably this memory is used in future.
-            mem.free(fieldinit);
-            */
-            fieldinit = NULL;
+
+            if (!nofree)
+            {
+                mem.free(fieldinit);
+                fieldinit = NULL;
+            }
         }
     }

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list