[geary/mjog/650-old-val-0-glib-critical: 7/7] Geary.Util.Logging.Source: Fix GLib `old_val > 0` critical



commit 8c43288bd051d1ab3c662071159975edfa055c05
Author: Michael Gratton <mike vee net>
Date:   Wed Mar 25 10:07:02 2020 +1100

    Geary.Util.Logging.Source: Fix GLib `old_val > 0` critical
    
    If a source object prints a log message from a destructor the
    engine's logging hander will attempt to ref it despite the object
    bing finalised, resulting in the critical.
    
    Fixes #650

 src/engine/util/util-logging.vala | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/src/engine/util/util-logging.vala b/src/engine/util/util-logging.vala
index 4161aad7..05f8234d 100644
--- a/src/engine/util/util-logging.vala
+++ b/src/engine/util/util-logging.vala
@@ -219,7 +219,10 @@ public interface Geary.Logging.Source : GLib.Object {
                                        va_list args) {
         if (flags == ALL || Logging.get_flags().is_any_set(flags)) {
             Context context = Context(Logging.DOMAIN, flags, levels, fmt, args);
-            Source? decorated = this;
+            // Don't attempt to this object if it is in the middle of
+            // being destructed, which can happen when logging from
+            // the destructor.
+            Source? decorated = (this.ref_count > 0) ? this : this.logging_parent;
             while (decorated != null) {
                 context.append_source(decorated);
                 decorated = decorated.logging_parent;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]