[NetworkManager-libreswan/lr/gtk-4.0: 1/12] shared: avoid unnecessary use of g_steal_pointer()




commit 6c392b55dd085906fd2d1e58ef35bff6c4811b8e
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Jan 14 18:13:30 2022 +0100

    shared: avoid unnecessary use of g_steal_pointer()
    
    This is only available in GLib 2.44, which we don't have.
    Moreover, it's kinda useless here.

 shared/utils.c | 48 +++++++++++++++++++++++++-----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)
---
diff --git a/shared/utils.c b/shared/utils.c
index acb237f..1d762cf 100644
--- a/shared/utils.c
+++ b/shared/utils.c
@@ -370,7 +370,7 @@ void
 nm_libreswan_detect_version (const char *path, gboolean *out_is_openswan, int *out_version, char 
**out_banner)
 {
        const char *argv[] = { path, "--version", NULL };
-       gs_free char *output = NULL;
+       char *output = NULL;
        const char* v;
 
        g_return_if_fail (out_is_openswan);
@@ -383,6 +383,8 @@ nm_libreswan_detect_version (const char *path, gboolean *out_is_openswan, int *o
                return;
 
        g_spawn_sync (NULL, (char **) argv, NULL, 0, NULL, NULL, &output, NULL, NULL, NULL);
+       if (!output)
+               return;
 
        /*
         * Examples:
@@ -391,29 +393,29 @@ nm_libreswan_detect_version (const char *path, gboolean *out_is_openswan, int *o
         * Linux Libreswan U4.2rc1/K(no kernel code presently loaded) on 5.6.15-300.fc32.x86_64
         */
 
-       if (output) {
-               v = strcasestr (output, "Openswan");
-               if (v) {
-                       v = v + strlen ("Openswan");
-                       *out_is_openswan = TRUE;
-               }
-
-               if (!v) {
-                       v = strcasestr (output, "Libreswan");
-                       if (v)
-                               v = v + strlen ("Libreswan");
-               }
+       v = strcasestr (output, "Openswan");
+       if (v) {
+               v = v + strlen ("Openswan");
+               *out_is_openswan = TRUE;
+       }
 
-               if (v) {
-                       while (g_ascii_isspace (*v))
-                               v++;
-                       if (*v == 'U')
-                               v++;
-                       if (g_ascii_isdigit (*v))
-                               *out_version = *v - '0';
-               }
+       if (!v) {
+               v = strcasestr (output, "Libreswan");
+               if (v)
+                       v = v + strlen ("Libreswan");
+       }
 
-               if (out_banner)
-                       *out_banner = g_steal_pointer (&output);
+       if (v) {
+               while (g_ascii_isspace (*v))
+                       v++;
+               if (*v == 'U')
+                       v++;
+               if (g_ascii_isdigit (*v))
+                       *out_version = *v - '0';
        }
+
+       if (out_banner)
+               *out_banner = output;
+       else
+               g_free (output);
 }


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