[gtk-vnc-devel] PATCH: Fix co-routine shutdown / release



When the co-routine shuts down we never call coroutine_release, so its
stack never gets unmapped. We also don't restore the 'current' pointer
to be the system coroutine. So if you later start a 2nd coroutine we're
switching state making the return state point to a now deleted coroutine.
All this makes the whole system very crash happy.

So this patch does a couple of things:

  - When the coroutine exits we call coroutine_release
  - When the coroutine exits we make the current context point to the
    system context
  - Ensures errors from swapcontext are passed back correctly, rather
    than return zero which indicates success.

With this patch in place, I can now successfully connect to a VNC server,
disconnect, and then re-connect again without megadeath.

Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
diff -r 7d6bc4441dc1 src/continuation.c
--- a/src/continuation.c	Fri Jul 06 14:39:12 2007 -0400
+++ b/src/continuation.c	Fri Jul 06 17:35:48 2007 -0400
@@ -43,9 +43,7 @@ int cc_swap(struct continuation *from, s
 	else if (to->exited == 1)
 		return 1;
 
-	swapcontext(&from->uc, &to->uc);
-
-	return 0;
+	return swapcontext(&from->uc, &to->uc);
 }
 /*
  * Local variables:
diff -r 7d6bc4441dc1 src/coroutine.c
--- a/src/coroutine.c	Fri Jul 06 14:39:12 2007 -0400
+++ b/src/coroutine.c	Fri Jul 06 17:37:21 2007 -0400
@@ -66,7 +66,7 @@ static struct coroutine *current;
 
 struct coroutine *coroutine_self(void)
 {
-	if (current == 0)
+	if (current == NULL)
 		current = &system;
 	return current;
 }
@@ -82,11 +82,13 @@ void *coroutine_swap(struct coroutine *f
 	if (ret == 0)
 		return from->data;
 	else if (ret == 1) {
+		coroutine_release(to);
+		current = &system;
 		to->exited = 1;
 		return to->data;
 	}
 
-	return 0;
+	return NULL;
 }
 
 void *yieldto(struct coroutine *to, void *arg)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]