Invoking PORTREADARRAY leaks memory whenever data is successfully read. The leak seems to be due to the bizare way in which lportreadarray data is read into the given array:
// now fill in the array
for (int i = 0; i < count; i++)
{
lsetitem(
cons_list(
make_intnode(i + getarrorg(obj)),
obj,
make_intnode(rxbuffer[i])));
}
You can see that it invokes lsetitem without freeing the cons_list argument to SETITEM.
This leak is reproducible in MSWLogo 6.5b and all version of FMSLogo up through 7.2.0.
How Reproducible:
Every Time
Steps to Reproduce:
Repro:
1) Connect a null modem from COM4 to COM5. This can be accomplished in software using an emulator called com0com.
2) Start an instance of FMSLogo and run this
PORTOPEN "com4
3) Start a second instance of FMSLogo, specifying a file name so that a second instance opens (instead of giving focus to the first instance). Run this
PORTOPEN "com5
REPEAT 1000 [ IGNORE PORTWRITECHAR 123 ]
4) On the first instance, run
SHOW NODES
IGNORE PORTREADARRAY 512 ARRAY 512
SHOW NODES
What Happens:
In Step 4, the second call to NODES shows about 1000 more nodes in use than the first call (the first item in the list), even though no additional state was saved in the FMSLogo environment.
Expected Result
In Step 4, the second call to NODES shows about the same number of nodes in use as the first call.
Note: this is easier to observe with debug version of FMSLogo, since that will print out every leaked allocations on shutdown. They look like:
Memory Leaks detected!
Leaked 86624 bytes in 2566 blocks
(id= 107266) 32 bytes at 0x0580E788: < 0 > DA DA DA DA 00 30 DA DA
(id= 107265) 32 bytes at 0x0580E750: < 0 > DA DA DA DA 00 30 DA DA
(id= 107264) 32 bytes at 0x0580E718: < 0 > DA DA DA DA 00 30 DA DA
...
(id= 39840) 32 bytes at 0x057E8AB0: < 0 > DA DA DA DA 00 30 DA DA
(id= 39839) 32 bytes at 0x057E87C0: < 0 > DA DA DA DA 00 30 DA DA
(id= 39838) 32 bytes at 0x057E8B20: < 0 > DA DA DA DA 00 30 DA DA
(id= 39837) 32 bytes at 0x057E8B58: < > DA DA DA DA 00 03 DA DA
(id= 39836) 32 bytes at 0x057E8B90: < > DA DA DA DA 00 03 DA DA
(id= 39834) 32 bytes at 0x057E86E0: < $ > DA DA DA DA 00 24 DA DA
(id= 39833) 2048 bytes at 0x057E6230: < ~ ~ > 90 8B 7E 05 C0 8C 7E 05
This is fixed by [r4573]. The fix will be available in FMSLogo 7.3.0.
Related
Commit: [r4573]