ref: 2ebc85236e6d92030b2707bc6a05c2b14d8bb24a
parent: b9d26a293eec4be3e9c46b6ce40d01a61646b8b8
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Wed Jun 19 16:13:55 EDT 2013
libdraw: fix allocscreen() memory leak with too many retries (from 9atom)
--- a/sys/src/libdraw/window.c
+++ b/sys/src/libdraw/window.c
@@ -22,14 +22,11 @@
s = malloc(sizeof(Screen));
if(s == 0)
return 0;
- SET(id);
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 == 0)
+ 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 0;
+
+ Found:
s->display = d;
s->id = id;
s->image = image;
--
⑨