[glib/mcatanzaro/coverity: 2/5] gapplication: fix arguments leak in error path




commit 79d4203a8e8b3ac73988ce7a312eabee6b0c3e15
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Wed Mar 31 11:44:23 2021 -0500

    gapplication: fix arguments leak in error path
    
    If this g_return_val_if_fail() is ever hit, then we leak arguments.
    This is not very important because if your code hits
    g_return_val_if_fail() you are invoking undefined behavior, a rather
    more serious problem, but let's replace it with g_critical() to be
    robust.
    
    Found by Coverity.

 gio/gapplication.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 5a43202a5..205117040 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -2524,7 +2524,12 @@ g_application_run (GApplication  *application,
 
   context = g_main_context_default ();
   acquired_context = g_main_context_acquire (context);
-  g_return_val_if_fail (acquired_context, 0);
+  if (acquired_context == NULL)
+    {
+      g_critical ("g_application_run() cannot acquire the default main context because it is already 
acquired by another thread!");
+      g_strfreev (arguments);
+      return;
+    }
 
   if (!G_APPLICATION_GET_CLASS (application)
         ->local_command_line (application, &arguments, &status))


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