GNOME Bugzilla – Bug 680931
lambdas within a Thread.create can deallocate data block before it's used
Last modified: 2012-08-02 17:50:14 UTC
Created attachment 220017 [details] vala file A lambda within 'Thread.create' (and I assume 'new Thread', but I have no way of testing it) allocates a user data block, but doesn't ref it before creating the thread, and unrefs it when the parent thread leaves the scope in which the thread was created. That means that the data block can be deallocated before any information is ever used. The relevant part of the c code generated was: GThread* main_inner_scope (Foo* foo) { ... Block1Data* _data1_; ... _tmp2_ = g_thread_create (___lambda2__gthread_func, _data1_, TRUE, &_inner_error_); ... block1_data_unref (_data1_); ... return result; } I think the g_thread_create call should be structured as '_tmp2_ = g_thread_create (___lambda2__gthread_func, block1_data_ref(_data1_), TRUE, &_inner_error_);', with a matching block1_data_unref within the lambda function after it's no longer needed.
Created attachment 220018 [details] resulting c code
*** This bug has been marked as a duplicate of bug 659619 ***
Oops, had marked this as a duplicate, but I don't think it really is as this post http://blogs.gnome.org/juergbi/2009/09/18/closures-and-asynchronous-methods-in-vala/ mentions that closures now should be valid.
commit d755870599b4f99a810bfbdbc27e708eb8b553ee Author: Jürg Billeter <j@bitron.ch> Date: Thu Aug 2 14:32:47 2012 +0200 Support [CCode (scope = "async")] attribute for delegates commit 7bc123e5c5113de3eafee909a6d4980550ece13f Author: Jürg Billeter <j@bitron.ch> Date: Thu Aug 2 14:33:35 2012 +0200 glib-2.0: Use async scope for GThreadFunc Fixes bug 680931.
Looks good. Thank you so much. Appreciate it.