Memory leak in the Sprite Library

Hello,

I just found out that there is a bug in the sprite library, as the memory allocated for the storage of a sprite (i.e. _buffer) never gets deallocated. The destructor of a sprite is missing.

I had to add the following code to Sprite.cpp:

===================================================

#include <string.h>

Sprite::Sprite(const Sprite &other)
{
operator=(other); // Call the assignment operator
}

Sprite::~Sprite()
{
if (!_buffer) return;
free(_buffer); // Make sure to free the buffer if it exists
}

Sprite& Sprite::operator=(const Sprite &other)
{
_width = other._width;
_height = other._height;
init(_width, _height);
memcpy(_buffer,other._buffer,_height);
return *this;
}

===================================================

And consequently the following lines in Sprite.h:

===================================================

Sprite(const Sprite &other);
~Sprite();
Sprite& operator=(const Sprite &other);

===================================================

I hope this helps other people playing around with the Sprite library and run into strange hangings of the program caused by the lack of free SRAM.

Perhaps this addition finds its way into a further release of the Arduino software.

Kind regards,

Jean-Claude

DO you have informed the makers of the sprite lib too ? (assuming their names are somewhere near where you downloaded it )?

The Sprite library is part of the Standard Libraries and is included in the Arduino framework: Libraries - Arduino Reference
I did not find out who is the maintainer of the library, will ask the guys from the Wiring project.