[retro-gtk] core: Fix a reference leak



commit 68b336cef11c5dcc5cb16478da6c18b8f2520d45
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun May 24 13:36:39 2020 +0200

    core: Fix a reference leak
    
    In 4b418a187df02897b0f6570888bf2cb5571500fc, g_set_object() was used to
    simplify some code. This is wrong because it takes a reference on the
    newer object, which the older code didn't do because it didn't need to.
    The extra reference wasn't removed, leading to a leak.
    
    This reverts that piece of code to what it was before the erroneous code
    cleanup.

 retro-runner/retro-core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
---
diff --git a/retro-runner/retro-core.c b/retro-runner/retro-core.c
index d4a6e3d..da7e1f5 100644
--- a/retro-runner/retro-core.c
+++ b/retro-runner/retro-core.c
@@ -1391,7 +1391,11 @@ retro_core_set_default_controller (RetroCore *self,
 {
   g_return_if_fail (RETRO_IS_CORE (self));
 
-  g_set_object (&self->default_controller, retro_controller_state_new (fd));
+  /* We cannot use g_set_object() because it would reference the new object,
+   * leaking its initial reference.
+   */
+  g_clear_object (&self->default_controller);
+  self->default_controller = retro_controller_state_new (fd);
 }
 
 void


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