After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 680931 - lambdas within a Thread.create can deallocate data block before it's used
lambdas within a Thread.create can deallocate data block before it's used
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.16.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2012-07-31 18:31 UTC by Adam Stark
Modified: 2012-08-02 17:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
vala file (1.53 KB, application/octet-stream)
2012-07-31 18:31 UTC, Adam Stark
Details
resulting c code (8.37 KB, application/octet-stream)
2012-07-31 18:32 UTC, Adam Stark
Details

Description Adam Stark 2012-07-31 18:31:35 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.
Comment 1 Adam Stark 2012-07-31 18:32:36 UTC
Created attachment 220018 [details]
resulting c code
Comment 2 Adam Stark 2012-07-31 19:10:50 UTC

*** This bug has been marked as a duplicate of bug 659619 ***
Comment 3 Adam Stark 2012-07-31 20:31:14 UTC
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.
Comment 4 Jürg Billeter 2012-08-02 12:35:06 UTC
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.
Comment 5 Adam Stark 2012-08-02 17:50:14 UTC
Looks good. Thank you so much.

Appreciate it.