fix memory leak in smart_placement (with area_list_remove) and fix the algo
This commit is contained in:
parent
593f92c24d
commit
9390abcfb4
15
client.c
15
client.c
|
@ -226,16 +226,19 @@ client_get_smart_geometry(Area geometry, int border, int screen)
|
||||||
{
|
{
|
||||||
Client *c;
|
Client *c;
|
||||||
Area newgeometry = { 0, 0, 0, 0, NULL };
|
Area newgeometry = { 0, 0, 0, 0, NULL };
|
||||||
Area *screen_geometry, *arealist = NULL, *r;
|
Area *screen_geometry, *tmp, *arealist = NULL, *r;
|
||||||
Bool found = False;
|
Bool found = False;
|
||||||
|
|
||||||
screen_geometry = p_new(Area, 1);
|
screen_geometry = p_new(Area, 1);
|
||||||
|
tmp = p_new(Area, 1);
|
||||||
|
|
||||||
*screen_geometry = screen_get_area(screen,
|
/* 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].statusbar,
|
||||||
&globalconf.screens[screen].padding);
|
&globalconf.screens[screen].padding);
|
||||||
|
|
||||||
area_list_push(&arealist, screen_geometry);
|
area_list_push(&arealist, tmp);
|
||||||
|
|
||||||
for(c = globalconf.clients; c; c = c->next)
|
for(c = globalconf.clients; c; c = c->next)
|
||||||
if(client_isvisible(c, screen))
|
if(client_isvisible(c, screen))
|
||||||
|
@ -272,12 +275,12 @@ client_get_smart_geometry(Area geometry, int border, int screen)
|
||||||
|
|
||||||
/* fix offscreen */
|
/* fix offscreen */
|
||||||
if(AREA_RIGHT(newgeometry) > AREA_RIGHT(*screen_geometry))
|
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))
|
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);
|
area_list_wipe(&arealist);
|
||||||
|
p_delete(&screen_geometry);
|
||||||
|
|
||||||
return newgeometry;
|
return newgeometry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -587,11 +587,11 @@ draw_color_new(Display *disp, int phys_screen, const char *colstr)
|
||||||
void
|
void
|
||||||
area_list_remove(Area **head, Area *elem)
|
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 = rnext)
|
||||||
|
{
|
||||||
for(r = *head; r; r = r->next)
|
rnext = r->next;
|
||||||
if(area_intersect_area(*r, *elem))
|
if(area_intersect_area(*r, *elem))
|
||||||
{
|
{
|
||||||
/* remove it from the list */
|
/* remove it from the list */
|
||||||
|
@ -606,7 +606,7 @@ area_list_remove(Area **head, Area *elem)
|
||||||
extra->y = r->y;
|
extra->y = r->y;
|
||||||
extra->width = AREA_LEFT(inter) - r->x;
|
extra->width = AREA_LEFT(inter) - r->x;
|
||||||
extra->height = r->height;
|
extra->height = r->height;
|
||||||
area_list_push(head, extra);
|
area_list_append(head, extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(AREA_TOP(inter) > AREA_TOP(*r))
|
if(AREA_TOP(inter) > AREA_TOP(*r))
|
||||||
|
@ -616,7 +616,7 @@ area_list_remove(Area **head, Area *elem)
|
||||||
extra->y = r->y;
|
extra->y = r->y;
|
||||||
extra->width = r->width;
|
extra->width = r->width;
|
||||||
extra->height = AREA_TOP(inter) - r->y;
|
extra->height = AREA_TOP(inter) - r->y;
|
||||||
area_list_push(head, extra);
|
area_list_append(head, extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(AREA_RIGHT(inter) < AREA_RIGHT(*r))
|
if(AREA_RIGHT(inter) < AREA_RIGHT(*r))
|
||||||
|
@ -626,7 +626,7 @@ area_list_remove(Area **head, Area *elem)
|
||||||
extra->y = r->y;
|
extra->y = r->y;
|
||||||
extra->width = AREA_RIGHT(*r) - AREA_RIGHT(inter);
|
extra->width = AREA_RIGHT(*r) - AREA_RIGHT(inter);
|
||||||
extra->height = r->height;
|
extra->height = r->height;
|
||||||
area_list_push(head, extra);
|
area_list_append(head, extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(AREA_BOTTOM(inter) < AREA_BOTTOM(*r))
|
if(AREA_BOTTOM(inter) < AREA_BOTTOM(*r))
|
||||||
|
@ -636,7 +636,11 @@ area_list_remove(Area **head, Area *elem)
|
||||||
extra->y = AREA_BOTTOM(inter);
|
extra->y = AREA_BOTTOM(inter);
|
||||||
extra->width = r->width;
|
extra->width = r->width;
|
||||||
extra->height = AREA_BOTTOM(*r) - AREA_BOTTOM(inter);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue