testsuite: fix memleak
authorBenjamin Otte <otte@redhat.com>
Sun, 4 Jun 2023 18:15:24 +0000 (20:15 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 5 Jun 2023 03:33:07 +0000 (05:33 +0200)
Also use the actual diff command we found instead of searching for it
again.

testsuite/testutils.c

index d1776da7b548ffcc91abfe5f7c9ae737b20ebfdf..6e8ba8e9401cc9d0c73ab778a69f7cce21dc77d2 100644 (file)
@@ -34,14 +34,16 @@ diff_with_file (const char  *file1,
                 gssize       len,
                 GError     **error)
 {
-  const char *command[] = { "diff", "-u", file1, NULL, NULL };
-  char *diff, *tmpfile;
+  char *diff_cmd, *diff, *tmpfile;
   int fd;
 
   diff = NULL;
 
-  if (g_find_program_in_path ("diff"))
+  diff_cmd = g_find_program_in_path ("diff");
+  if (diff_cmd)
     {
+      const char *command[] = { diff_cmd, "-u", file1, NULL, NULL };
+
       if (len < 0)
         len = strlen (text);
 
@@ -65,7 +67,7 @@ diff_with_file (const char  *file1,
       g_spawn_sync (NULL,
                     (char **) command,
                     NULL,
-                    G_SPAWN_SEARCH_PATH,
+                    0,
                     NULL, NULL,
                     &diff,
                     NULL, NULL,
@@ -74,6 +76,7 @@ diff_with_file (const char  *file1,
 done:
       g_unlink (tmpfile);
       g_free (tmpfile);
+      g_free (diff_cmd);
     }
   else
     {