diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-10-14 19:48:46 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2012-10-14 19:48:46 +0200 |
commit | 2f732e9a850f5549b391072cd6dd13ea4b0a8185 (patch) | |
tree | 78ed452d20b23ce0995fbaffb5825ffb93200816 /sys/src/9/port/segment.c | |
parent | fef6ff96ad17620bd084471f561382d33e52c9a5 (diff) |
kernel: attachimage / exec error handling
attachimage()'s approach to handling newseg() error is flawed:
a) the the image is on the hash table, but ref is still 0, and
there is no segment/pages attached to it so nobody is going to
reclaim / putimage() it -> leak
b) calling pexit() would deadlock us because exec has acquired
up->seglock when calling attachimage(), so this would just deadlock.
the fix does the following:
attachimage() will putimage() and nexterror() if newseg() fails
instead of pexit(). this is less surprising.
exec now keeps the condition variable commit which is set once
we are commited / reached the point of no return and check this
variable in the highest waserror() handler and pexit() us there.
this way we have released up all the locks and pexit() will
cleanup.
note: this bug shouldnt us hit in with the current newseg()
implementation as it uses smalloc() which would wait to
satisfy the allocation instead of erroring.
Diffstat (limited to 'sys/src/9/port/segment.c')
-rw-r--r-- | sys/src/9/port/segment.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/src/9/port/segment.c b/sys/src/9/port/segment.c index 54c10ebee..98e9cbfa0 100644 --- a/sys/src/9/port/segment.c +++ b/sys/src/9/port/segment.c @@ -285,14 +285,14 @@ found: unlock(&imagealloc); if(i->s == 0) { - /* Disaster after commit in exec */ + i->ref++; if(waserror()) { unlock(i); - pexit(Enovmem, 1); + putimage(i); + nexterror(); } i->s = newseg(type, base, len); i->s->image = i; - i->ref++; poperror(); } else |