summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-06-19 20:13:55 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-06-19 20:13:55 +0200
commit82b243b5adb7b22e1a97ad895c6eb89fe33e4097 (patch)
tree1155851446fa0f54f0076117e413c033f6f24479
parent5bb8203bf6cf2db988fc61ffaf8bf39aa30fabfe (diff)
downloadplan9front-82b243b5adb7b22e1a97ad895c6eb89fe33e4097.tar.xz
libdraw: fix allocscreen() memory leak with too many retries (from 9atom)
-rw-r--r--sys/src/libdraw/window.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/sys/src/libdraw/window.c b/sys/src/libdraw/window.c
index 4c734208b..84ecb1fc9 100644
--- a/sys/src/libdraw/window.c
+++ b/sys/src/libdraw/window.c
@@ -22,14 +22,11 @@ allocscreen(Image *image, Image *fill, int public)
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 @@ allocscreen(Image *image, Image *fill, int public)
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;