don't return invalid Screen* if we've exhausted our tries. Reference: /n/sources/patch/maybe/window-leak Date: Sun Feb 23 16:14:25 CET 2014 Signed-off-by: quanstro@quanstro.net --- /sys/src/libdraw/window.c Sun Feb 23 16:11:00 2014 +++ /sys/src/libdraw/window.c Sun Feb 23 16:10:58 2014 @@ -20,16 +20,13 @@ return 0; } s = malloc(sizeof(Screen)); - if(s == 0) - return 0; - SET(id); + if(s == nil) + return nil; for(try=0; try<25; try++){ /* loop until find a free id */ a = bufimage(d, 1+4+4+4+1); - if(a == 0){ - free(s); - return 0; - } + if(a == nil) + break; id = ++screenid; a[0] = 'A'; BPLONG(a+1, id); @@ -37,8 +34,12 @@ BPLONG(a+9, fill->id); a[13] = public; if(flushimage(d, 0) != -1) - break; + goto found; } + free(s); + return nil; +found: + werrstr(""); s->display = d; s->id = id; s->image = image;