Fixed some memory leaks.

master
Jason von Nieda 13 years ago
parent b364affd0e
commit d4b36291f5
  1. 12
      ScreenUi.cpp
  2. 7
      ScreenUi.h

@ -124,7 +124,9 @@ Container::Container() {
} }
Container::~Container() { Container::~Container() {
if (components_) {
free(components_); free(components_);
}
} }
void Container::update(Screen *screen) { void Container::update(Screen *screen) {
@ -154,11 +156,7 @@ void Container::repaint() {
void Container::add(Component *component, int8_t x, int8_t y) { void Container::add(Component *component, int8_t x, int8_t y) {
if (!components_ || componentsLength_ <= componentCount_) { if (!components_ || componentsLength_ <= componentCount_) {
uint8_t newComponentsLength = (componentsLength_ * 2) + 1; uint8_t newComponentsLength = (componentsLength_ * 2) + 1;
Component** newComponents = (Component**) malloc(newComponentsLength * sizeof(Component*)); Component** newComponents = (Component**) realloc(newComponentsLength * sizeof(Component*));
for (int i = 0; i < componentCount_; i++) {
newComponents[i] = components_[i];
}
free(components_);
components_ = newComponents; components_ = newComponents;
componentsLength_ = newComponentsLength; componentsLength_ = newComponentsLength;
} }
@ -354,6 +352,10 @@ List::List(uint8_t maxItems) : Label(NULL) {
captured_ = false; captured_ = false;
} }
List::~List() {
free(items_);
}
void List::addItem(const char *item) { void List::addItem(const char *item) {
items_[itemCount_++] = (char*) item; items_[itemCount_++] = (char*) item;
if (text_ == NULL) { if (text_ == NULL) {

@ -53,7 +53,7 @@ class CharSet {
class RangeCharSet : public CharSet { class RangeCharSet : public CharSet {
public: public:
RangeCharSet(int rangeCount, ...); RangeCharSet(int rangeCount, ...);
~RangeCharSet(); virtual ~RangeCharSet();
virtual int charAt(int index); virtual int charAt(int index);
virtual unsigned char size(); virtual unsigned char size();
private: private:
@ -125,7 +125,7 @@ class Component {
class Container : public Component { class Container : public Component {
public: public:
Container(); Container();
~Container(); virtual ~Container();
virtual void add(Component *component, int8_t x, int8_t y); virtual void add(Component *component, int8_t x, int8_t y);
virtual void update(Screen *screen); virtual void update(Screen *screen);
// Paints any dirty child components. // Paints any dirty child components.
@ -258,6 +258,7 @@ class Checkbox : public Label {
class List : public Label { class List : public Label {
public: public:
List(uint8_t maxItems); List(uint8_t maxItems);
virtual ~List();
void addItem(const char *item); void addItem(const char *item);
const char *selectedItem() { return items_[selectedIndex_]; } const char *selectedItem() { return items_[selectedIndex_]; }
uint8_t selectedIndex() { return selectedIndex_; } uint8_t selectedIndex() { return selectedIndex_; }
@ -333,7 +334,7 @@ class ScrollContainer : public Container {
// better than adding this property to every other object or walking // better than adding this property to every other object or walking
// the tree to find it. // the tree to find it.
ScrollContainer(Screen *screen, uint8_t width, uint8_t height); ScrollContainer(Screen *screen, uint8_t width, uint8_t height);
~ScrollContainer(); virtual ~ScrollContainer();
virtual void paint(Screen *screen); virtual void paint(Screen *screen);
virtual bool dirty(); virtual bool dirty();
#ifdef SCREENUI_DEBUG #ifdef SCREENUI_DEBUG

Loading…
Cancel
Save