Prevent some memory leaks

This commit is contained in:
Sanel Zukan 2012-04-19 12:49:30 +00:00
parent 6b78cb3b0a
commit 8aa9d550b2
3 changed files with 26 additions and 5 deletions

View File

@ -22,8 +22,11 @@ static long get_number(const char *ln) {
int i = 1;
for(char *p = strtok(s, " "); p; p = strtok(NULL, " "), i++) {
if(i == 2)
return atol(p);
if(i == 2) {
long ret = atol(p);
free(s);
return ret;
}
}
free(s);

View File

@ -84,7 +84,7 @@ static void maximize_cb(Fl_Widget*, void *b) {
redraw_whole_panel(bb);
}
TaskButton::TaskButton(int X, int Y, int W, int H, const char *l) : Fl_Button(X, Y, W, H, l), xid(0) {
TaskButton::TaskButton(int X, int Y, int W, int H, const char *l) : Fl_Button(X, Y, W, H, l), xid(0), image_alloc(false) {
box(FL_UP_BOX);
align(FL_ALIGN_INSIDE | FL_ALIGN_LEFT | FL_ALIGN_CLIP);
@ -97,6 +97,18 @@ TaskButton::TaskButton(int X, int Y, int W, int H, const char *l) : Fl_Button(X,
image(image_window);
}
TaskButton::~TaskButton() {
clear_image();
}
void TaskButton::clear_image(void) {
if(image_alloc && image())
delete image();
image(NULL);
image_alloc = false;
}
void TaskButton::draw(void) {
Fl_Color col = value() ? selection_color() : color();
draw_box(value() ? (down_box() ? down_box() : fl_down(box())) : box(), col);
@ -240,5 +252,7 @@ void TaskButton::update_image_from_xid(void) {
img = scaled;
}
clear_image();
image(img);
image_alloc = true;
}

View File

@ -7,11 +7,15 @@
class TaskButton : public Fl_Button {
private:
/* window ID this button handles */
Window xid;
Atom net_wm_icon;
Window xid;
bool image_alloc;
Atom net_wm_icon;
void clear_image(void);
public:
TaskButton(int X, int Y, int W, int H, const char *l = 0);
~TaskButton();
void draw(void);
void display_menu(void);