[Spice-devel] [spice-gtk RFC 0/3] coroutine: Make signal/notify coroutine code more robust against unexpected coroutine_init()

Christophe Fergeau cfergeau at redhat.com
Mon Feb 23 02:55:45 PST 2015


Hey,

Before the recent rework of disconnect/channel_reset, it was possible to get in a situation where
an idle would get queued, then an attempt to emit a signal from coroutine context would be attempted.
The first idle would run, call coroutine_init() which would reset the coroutine state, and then the
signal emission idle would run in an invalid context (the stack allocated
signal_data data would no longer be valid), causing a hard to diagnose crash.
This series tries to improve that by showing a warning when coroutine_init() is called while
a signal/notify idle is queued.
For now this is only done for the ucontext implementation, depending on where this RFC goes,
I'll add support to the other variants. While this adds some code to coroutine_init() and a member to
struct coroutine, the only thing which is needed is some way to run a check
when coroutine_init() gets called. For example, an alternative could be a g_coroutine_init() wrapper
doing the check and then calling into coroutine_init().
Patch 3/3 is a bit ugly because of the hoops it has to go through in order to safely free some
allocated memory. In my opinion, it's plenty fine to decide that we'll leak a bit of memory when
the warning added in 2/3 triggers.

Christophe



More information about the Spice-devel mailing list