[mutter] test-utils: Only initialize client when we're returning it



commit 506e06589b7feabd184b90bf5ac38ec83cefd92c
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Jul 9 11:49:18 2019 +0200

    test-utils: Only initialize client when we're returning it
    
    test_client_new might return early if conditions are not met, leaving some
    allocated data around without freeing it.
    
    Since we're not using the client before, there's no need to initialize it early
    and just initialize it when it's going to be returned.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/1195

 src/tests/test-utils.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/src/tests/test-utils.c b/src/tests/test-utils.c
index cfade80c5..28cf97164 100644
--- a/src/tests/test-utils.c
+++ b/src/tests/test-utils.c
@@ -427,7 +427,7 @@ test_client_new (const char          *id,
                  MetaWindowClientType type,
                  GError             **error)
 {
-  TestClient *client = g_new0 (TestClient, 1);
+  TestClient *client;
   GSubprocessLauncher *launcher;
   GSubprocess *subprocess;
   MetaWaylandCompositor *compositor;
@@ -462,6 +462,7 @@ test_client_new (const char          *id,
   if (!subprocess)
     return NULL;
 
+  client = g_new0 (TestClient, 1);
   client->type = type;
   client->id = g_strdup (id);
   client->cancellable = g_cancellable_new ();


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