mirror of
https://github.com/awesomeWM/awesome
synced 2024-11-17 07:47:41 +01:00
fix memory leak in smart_placement (with area_list_remove) and fix the algo
This commit is contained in:
parent
593f92c24d
commit
9390abcfb4
3 changed files with 23 additions and 17 deletions
19
client.c
19
client.c
|
@ -226,16 +226,19 @@ client_get_smart_geometry(Area geometry, int border, int screen)
|
|||
{
|
||||
Client *c;
|
||||
Area newgeometry = { 0, 0, 0, 0, NULL };
|
||||
Area *screen_geometry, *arealist = NULL, *r;
|
||||
Area *screen_geometry, *tmp, *arealist = NULL, *r;
|
||||
Bool found = False;
|
||||
|
||||
screen_geometry = p_new(Area, 1);
|
||||
tmp = p_new(Area, 1);
|
||||
|
||||
*screen_geometry = screen_get_area(screen,
|
||||
globalconf.screens[screen].statusbar,
|
||||
&globalconf.screens[screen].padding);
|
||||
/* we need tmp because it may be free'd by in
|
||||
* the area_list_remove process */
|
||||
*screen_geometry = *tmp = screen_get_area(screen,
|
||||
globalconf.screens[screen].statusbar,
|
||||
&globalconf.screens[screen].padding);
|
||||
|
||||
area_list_push(&arealist, screen_geometry);
|
||||
area_list_push(&arealist, tmp);
|
||||
|
||||
for(c = globalconf.clients; c; c = c->next)
|
||||
if(client_isvisible(c, screen))
|
||||
|
@ -272,12 +275,12 @@ client_get_smart_geometry(Area geometry, int border, int screen)
|
|||
|
||||
/* fix offscreen */
|
||||
if(AREA_RIGHT(newgeometry) > AREA_RIGHT(*screen_geometry))
|
||||
newgeometry.x = screen_geometry->x + screen_geometry->width - newgeometry.width - 2 * border;
|
||||
newgeometry.x = screen_geometry->x + screen_geometry->width - (newgeometry.width + 2 * border);
|
||||
|
||||
if(AREA_BOTTOM(newgeometry) > AREA_BOTTOM(*screen_geometry))
|
||||
newgeometry.y = screen_geometry->y + screen_geometry->height - newgeometry.height - 2 * border;
|
||||
|
||||
newgeometry.y = screen_geometry->y + screen_geometry->height - (newgeometry.height + 2 * border);
|
||||
area_list_wipe(&arealist);
|
||||
p_delete(&screen_geometry);
|
||||
|
||||
return newgeometry;
|
||||
}
|
||||
|
|
|
@ -587,11 +587,11 @@ draw_color_new(Display *disp, int phys_screen, const char *colstr)
|
|||
void
|
||||
area_list_remove(Area **head, Area *elem)
|
||||
{
|
||||
Area *r, inter, *extra;
|
||||
Area *r, inter, *extra, *rnext;
|
||||
|
||||
area_list_detach(head, elem);
|
||||
|
||||
for(r = *head; r; r = r->next)
|
||||
for(r = *head; r; r = rnext)
|
||||
{
|
||||
rnext = r->next;
|
||||
if(area_intersect_area(*r, *elem))
|
||||
{
|
||||
/* remove it from the list */
|
||||
|
@ -606,7 +606,7 @@ area_list_remove(Area **head, Area *elem)
|
|||
extra->y = r->y;
|
||||
extra->width = AREA_LEFT(inter) - r->x;
|
||||
extra->height = r->height;
|
||||
area_list_push(head, extra);
|
||||
area_list_append(head, extra);
|
||||
}
|
||||
|
||||
if(AREA_TOP(inter) > AREA_TOP(*r))
|
||||
|
@ -616,7 +616,7 @@ area_list_remove(Area **head, Area *elem)
|
|||
extra->y = r->y;
|
||||
extra->width = r->width;
|
||||
extra->height = AREA_TOP(inter) - r->y;
|
||||
area_list_push(head, extra);
|
||||
area_list_append(head, extra);
|
||||
}
|
||||
|
||||
if(AREA_RIGHT(inter) < AREA_RIGHT(*r))
|
||||
|
@ -626,7 +626,7 @@ area_list_remove(Area **head, Area *elem)
|
|||
extra->y = r->y;
|
||||
extra->width = AREA_RIGHT(*r) - AREA_RIGHT(inter);
|
||||
extra->height = r->height;
|
||||
area_list_push(head, extra);
|
||||
area_list_append(head, extra);
|
||||
}
|
||||
|
||||
if(AREA_BOTTOM(inter) < AREA_BOTTOM(*r))
|
||||
|
@ -636,9 +636,13 @@ area_list_remove(Area **head, Area *elem)
|
|||
extra->y = AREA_BOTTOM(inter);
|
||||
extra->width = r->width;
|
||||
extra->height = AREA_BOTTOM(*r) - AREA_BOTTOM(inter);
|
||||
area_list_push(head, extra);
|
||||
area_list_append(head, extra);
|
||||
}
|
||||
|
||||
/* delete the elem since we removed it from the list */
|
||||
p_delete(&r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||
|
|
1
xutil.c
1
xutil.c
|
@ -103,7 +103,6 @@ xgettextprop(Window w, Atom atom, char *text, ssize_t textlen)
|
|||
{
|
||||
char **list = NULL;
|
||||
int n;
|
||||
|
||||
XTextProperty name;
|
||||
|
||||
if(!text || !textlen)
|
||||
|
|
Loading…
Reference in a new issue