Critical from a GDateTime being freed more than it is being ref'ed
Just ran into a problem on a Geary branch I'm working on. The following code is causing a g_date_time_unref: assertion 'datetime->ref_count > 0' failed
critical when the class this method belongs to is finalised, because a GDateTime is being free'ed once to many times:
private void stock_from_gmime() throws RFC822Error {
GMime.Message message = …;
…
var date = message.get_date();
if (date != null) {
this.date = new Date(date);
}
…
}
AFAICT the GMimeMessage class is doing the right thing, and the Date class above is an internal Geary class that simply sets the GDateTime as a property, and looking at the C for that is also doing the right thing.
What seems to be wrong is that g_date_time_unref(date)
is being called at the end of this method, without g_date_time_ref(date)
being called on the value returned by g_mime_message_get_date()
:
geary_rf_c822_message_stock_from_gmime (GearyRFC822Message* self,
GError** error)
{
…
#line 904 "../src/engine/rfc822/rfc822-message.vala"
_tmp29_ = message;
#line 904 "../src/engine/rfc822/rfc822-message.vala"
_tmp30_ = g_mime_message_get_date (_tmp29_);
#line 904 "../src/engine/rfc822/rfc822-message.vala"
date = _tmp30_;
#line 905 "../src/engine/rfc822/rfc822-message.vala"
_tmp31_ = date;
#line 905 "../src/engine/rfc822/rfc822-message.vala"
if (_tmp31_ != NULL) {
#line 7737 "rfc822-message.c"
GDateTime* _tmp32_;
GearyRFC822Date* _tmp33_;
GearyRFC822Date* _tmp34_;
#line 906 "../src/engine/rfc822/rfc822-message.vala"
_tmp32_ = date;
#line 906 "../src/engine/rfc822/rfc822-message.vala"
_tmp33_ = geary_rf_c822_date_new (_tmp32_);
#line 906 "../src/engine/rfc822/rfc822-message.vala"
_tmp34_ = _tmp33_;
#line 906 "../src/engine/rfc822/rfc822-message.vala"
geary_email_header_set_set_date (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_TYPE_EMAIL_HEADER_SET, GearyEmailHeaderSet), _tmp34_);
#line 906 "../src/engine/rfc822/rfc822-message.vala"
_g_object_unref0 (_tmp34_);
#line 7751 "rfc822-message.c"
}
…
#line 890 "../src/engine/rfc822/rfc822-message.vala"
_g_date_time_unref0 (date);
…
}
Not sure if the root cause use the GLib or GMime VAPI, or a vala issue though.