It would probably make more sense just to move the actual cleanup to wg_parser_destroy(), although in order to do that we'll also need to call wg_parser_destroy() on the quartz parser earlier.
I don't think that would change the issue substantially. The problem is that currently there is no synchronization between when the the reader thread calling `wg_parser_stream_get_buffer()` is done using the stream resources (particularly the condition variables) and when these resources are destroyed. Moving destruction to `wg_parser_destroy()`, in itself, wouldn't change much, because the client could call `RequestSample()` and then immediately `Shutdown()` and `Release()`.