-
Notifications
You must be signed in to change notification settings - Fork 518
Closed
Labels
Description
The intended usage of setFirmwareVersion is (I suspect) that it is called at most once, in which case the memory it allocates will be retained for the lifetime of the sketch (and therefore not leaked, even though it is never deallocated). However, if setFirmwareVersion is called multiple times, previously allocated memory is not released, leading to a memory leak.
Here's a unit test which demonstrates the issue (using ArduinoUnit and the MemoryFree library - from http://playground.arduino.cc/Code/AvailableMemory):
test(setFirmwareVersionDoesNotLeakMemory)
{
Firmata.setFirmwareVersion(1, 0);
int initialMemory = freeMemory();
Firmata.setFirmwareVersion(1, 0);
assertEquals(0, initialMemory - freeMemory());
}
The output indicates that 20 bytes are leaked:
Equality assertion failed in 'setFirmwareVersionDoesNotLeakMemory'
on line 140: expected '0' but was '20'