[Spice-devel] [spice-gtk] Fix leak of mmapped memory when cc_init() fails

Christophe Fergeau cfergeau at redhat.com
Mon Nov 18 09:16:00 PST 2013


---
 gtk/coroutine_ucontext.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/gtk/coroutine_ucontext.c b/gtk/coroutine_ucontext.c
index f4ff22e..4689166 100644
--- a/gtk/coroutine_ucontext.c
+++ b/gtk/coroutine_ucontext.c
@@ -65,6 +65,8 @@ static void coroutine_trampoline(struct continuation *cc)
 
 int coroutine_init(struct coroutine *co)
 {
+	int inited;
+
 	if (co->stack_size == 0)
 		co->stack_size = 16 << 20;
 
@@ -80,7 +82,14 @@ int coroutine_init(struct coroutine *co)
 	co->cc.release = _coroutine_release;
 	co->exited = 0;
 
-	return cc_init(&co->cc);
+	inited = cc_init(&co->cc);
+	if (inited != 0) {
+		munmap(co->cc.stack, co->cc.stack_size);
+		co->cc.stack = NULL;
+		co->exited = 1;
+	}
+
+	return inited;
 }
 
 #if 0
-- 
1.8.4.2



More information about the Spice-devel mailing list