Fixed some memory leaks.

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

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

@ -53,7 +53,7 @@ class CharSet {
class RangeCharSet : public CharSet {
public:
RangeCharSet(int rangeCount, ...);
~RangeCharSet();
virtual ~RangeCharSet();
virtual int charAt(int index);
virtual unsigned char size();
private:
@ -125,7 +125,7 @@ class Component {
class Container : public Component {
public:
Container();
~Container();
virtual ~Container();
virtual void add(Component *component, int8_t x, int8_t y);
virtual void update(Screen *screen);
// Paints any dirty child components.
@ -258,6 +258,7 @@ class Checkbox : public Label {
class List : public Label {
public:
List(uint8_t maxItems);
virtual ~List();
void addItem(const char *item);
const char *selectedItem() { return items_[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
// the tree to find it.
ScrollContainer(Screen *screen, uint8_t width, uint8_t height);
~ScrollContainer();
virtual ~ScrollContainer();
virtual void paint(Screen *screen);
virtual bool dirty();
#ifdef SCREENUI_DEBUG

Loading…
Cancel
Save