fix double free bug, simplify error handling, reduce X11 calls

This commit is contained in:
MvA 2022-09-11 15:04:39 +02:00 committed by Dan Cross
parent 3e764832bc
commit 846f724983

View file

@ -24,7 +24,6 @@ struct Win {
XDisplay *dpy;
XWindow root;
Atom net_active_window;
Reprog *exclude = nil;
Win *win;
@ -38,8 +37,7 @@ Font *font;
Image *lightblue;
enum
{
enum {
PAD = 3,
MARGIN = 5
};
@ -71,7 +69,7 @@ estrdup(char *s)
s = strdup(s);
if(s==nil)
sysfatal("out of memory allocating");
return s;
return(s);
}
char*
@ -90,10 +88,10 @@ getproperty(XWindow w, Atom a)
if(s!=0){
XFree(p);
return nil;
return(nil);
}
return (char*)p;
return((char*)p);
}
XWindow
@ -109,14 +107,14 @@ findname(XWindow w)
p = getproperty(w, XA_WM_NAME);
if(p){
free(p);
return w;
return(w);
}
net_wm_name = XInternAtom(dpy, "_NET_WM_NAME", FALSE);
p = getproperty(w, net_wm_name);
if(p){
free(p);
return w;
return(w);
}
rwin = 0;
@ -144,6 +142,7 @@ wcmp(const void *w1, const void *w2)
}
/* unicode-aware case-insensitive strcmp, taken from golangs gc/subr.c */
int
_cistrcmp(char *p, char *q)
{
@ -194,7 +193,6 @@ refreshwin(void)
XFree(xwin);
return;
}
qsort(xwin, nxwin, sizeof(xwin[0]), wcmp);
nw = 0;
@ -257,7 +255,6 @@ refreshwin(void)
mwin += 8;
win = erealloc(win, mwin * sizeof(win[0]));
}
win[nw].n = xwin[i];
win[nw].label = estrdup(label);
win[nw].dirty = 1;
@ -455,6 +452,8 @@ main(int argc, char **argv)
if(argc)
usage();
einit(Emouse | Ekeyboard);
Etimer = etimer(0, 1000);
dpy = XOpenDisplay("");
if(dpy==nil)
@ -471,14 +470,10 @@ main(int argc, char **argv)
if(font==nil)
sysfatal("font '%s' not found", fontname);
einit(Emouse | Ekeyboard);
Etimer = etimer(0, 1000);
XSetErrorHandler(winwatchxerrorhandler);
refreshwin();
redraw(screen, 1);
for(;;){
switch(eread(Emouse|Ekeyboard|Etimer, &e)){
case Ekeyboard: