"APPLY [ [] [unknown] ] []" leaks memory
A Logo programming environment for Microsoft Windows
Brought to you by:
david_costanzo
If APPLY attempts to run a "named slot template" instruction list and it has an unknown procedure, FMSLogo leaks memory.
I have reproduced this as far back as FMSLogo 6.11.0. In FMSLogo 6.10.1, the leak is not reproducible. A leak is reproducible in MSWLogo 6.5b, but I suspect that's a different memory leak that was fixed before FMSLogo 6.10.0.
How Reproducible:
Every Time
Steps to Reproduce:
SHOW NODES
REPEAT 1000 [ CATCH "error (LIST "APPLY (LIST [] (LIST "unknown) ) [] ) ]
SHOW NODES
What Happens:
The first item in the second NODES printout is several thousand larger than the first item in the first NODES printout
Expected Result:
The first item in the second NODES printout is about the same (within a hundred) of the first item in the first NODES printout.
The bug is not limited to an unknown procedure, it seems like any "named slot template" instruction will cause it. For example, this also reproduces the leak:
At first glance of the leaked nodes, it looks the node representing the anonymous function is leaked because the "treeification" creates a circular reference that is only broken if the node is explicitly untreeified.
In looking at CHANGELOG.TXT for version 6.11.0, I don't see anything that could have introduced this.
This is fixed by combination of [r6323], [r6326], [r6332], and [r6343]. The fix will be available in FMSLogo 8.6.0.
The problem was a cycle that was created in the treeification of a procedure body. Each line in the bodylist became a TREE, which is used to get the parse tree of the line. In turn, the first expression each TREE was made into a LINE, which has a reference back to the bodylist line. This was introduced in 6.11.0 by [r1570] in a fix for Bug #126 that made FMSLogo look more like UCBLogo. This change removed code from treeify_bodylist() that untreeified the line after treeifying it. The correponding code is commented in out in make_tree_from_body() in paren.c in UCBLogo, which is why I removed it from FMSLogo:
The circular reference is not a problem in UCBLogo because it has a mark-and-sweep garbage collector. It's a problem in FMSLogo because it uses reference counting and so the circular reference must be broken by an explicit untreeify call. I couldn't find a place to untreeify anonymous procedures, so I thought it was better not to have a cycle in the first place. Overall, this made the code base simpler because it made the structure of a treeified procedure simpler and removed the need to untreeify when procedures are cleaned up.
It seems silly to treeify the line, then untreeify it, so I reworked the treeification process to be able to create the tree of a line without making it a TREE.
Related
Bugs: #126
Commit: [r1570]
Commit: [r6323]
Commit: [r6326]
Commit: [r6332]
Commit: [r6343]