Skip to content

setFirmwareVersion leaks memory #36

@mmurdoch

Description

@mmurdoch

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions