about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/cmd_ac.c84
-rw-r--r--src/common.c8
-rw-r--r--src/common.h2
3 files changed, 23 insertions, 71 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index e48e0ae2..f424d401 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -2381,7 +2381,7 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo
     char* found = NULL;
 
     gboolean result;
-    gchar** args = parse_args(input, 2, 8, &result);
+    auto_gcharv gchar** args = parse_args(input, 2, 8, &result);
 
     if (result && ((strcmp(args[0], "add") == 0) || (strcmp(args[0], "update") == 0))) {
         gboolean space_at_end = g_str_has_suffix(input, " ");
@@ -2392,7 +2392,6 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo
             found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -2403,7 +2402,6 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo
             found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice, previous, NULL);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -2413,7 +2411,6 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo
             found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -2424,7 +2421,6 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo
             found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice, previous, NULL);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -2434,7 +2430,6 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo
             found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -2445,14 +2440,11 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo
             found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice, previous, NULL);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
     }
 
-    g_strfreev(args);
-
     found = autocomplete_param_with_func(input, "/bookmark remove", bookmark_find, previous, NULL);
     if (found) {
         return found;
@@ -2654,7 +2646,7 @@ _otr_autocomplete(ProfWin* window, const char* const input, gboolean previous)
     // /otr policy always user@server.com
     if (conn_status == JABBER_CONNECTED) {
         gboolean result;
-        gchar** args = parse_args(input, 2, 3, &result);
+        auto_gcharv gchar** args = parse_args(input, 2, 3, &result);
         if (result && (strcmp(args[0], "policy") == 0)) {
             GString* beginning = g_string_new("/otr ");
             g_string_append(beginning, args[0]);
@@ -2666,11 +2658,9 @@ _otr_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             found = autocomplete_param_with_func(input, beginning->str, roster_contact_autocomplete, previous, NULL);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
-        g_strfreev(args);
     }
 
     found = autocomplete_param_with_ac(input, "/otr policy", otr_policy_ac, TRUE, previous);
@@ -2718,7 +2708,7 @@ _pgp_autocomplete(ProfWin* window, const char* const input, gboolean previous)
     }
 
     gboolean result;
-    gchar** args = parse_args(input, 2, 3, &result);
+    auto_gcharv gchar** args = parse_args(input, 2, 3, &result);
     if ((strncmp(input, "/pgp", 4) == 0) && (result == TRUE)) {
         GString* beginning = g_string_new("/pgp ");
         g_string_append(beginning, args[0]);
@@ -2729,11 +2719,9 @@ _pgp_autocomplete(ProfWin* window, const char* const input, gboolean previous)
         found = autocomplete_param_with_func(input, beginning->str, p_gpg_autocomplete_key, previous, NULL);
         g_string_free(beginning, TRUE);
         if (found) {
-            g_strfreev(args);
             return found;
         }
     }
-    g_strfreev(args);
 
     if (conn_status == JABBER_CONNECTED) {
         found = autocomplete_param_with_func(input, "/pgp setkey", roster_barejid_autocomplete, previous, NULL);
@@ -2847,7 +2835,7 @@ _omemo_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             int num_tokens = count_tokens(input);
             if (num_tokens == 4) {
                 gboolean result;
-                gchar** args = parse_args(input, 2, 3, &result);
+                auto_gcharv gchar** args = parse_args(input, 2, 3, &result);
                 if (result) {
                     auto_gchar gchar* jid = g_strdup(args[1]);
                     found = autocomplete_param_no_with_func(input, "/omemo trust", 4, omemo_fingerprint_autocomplete, previous, jid);
@@ -2874,7 +2862,7 @@ _omemo_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             int num_tokens = count_tokens(input);
             if (num_tokens == 4) {
                 gboolean result;
-                gchar** args = parse_args(input, 2, 3, &result);
+                auto_gcharv gchar** args = parse_args(input, 2, 3, &result);
                 if (result) {
                     auto_gchar gchar* jid = g_strdup(args[1]);
                     found = autocomplete_param_no_with_func(input, "/omemo untrust", 4, omemo_fingerprint_autocomplete, previous, jid);
@@ -3410,7 +3398,7 @@ _affiliation_autocomplete(ProfWin* window, const char* const input, gboolean pre
         gboolean parse_result;
         Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid);
 
-        gchar** args = parse_args(input, 2, 3, &parse_result);
+        auto_gcharv gchar** args = parse_args(input, 2, 3, &parse_result);
 
         if ((strncmp(input, "/affiliation", 12) == 0) && (parse_result == TRUE)) {
             GString* beginning = g_string_new("/affiliation ");
@@ -3423,12 +3411,9 @@ _affiliation_autocomplete(ProfWin* window, const char* const input, gboolean pre
             result = autocomplete_param_with_ac(input, beginning->str, jid_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (result) {
-                g_strfreev(args);
                 return result;
             }
         }
-
-        g_strfreev(args);
     }
 
     result = autocomplete_param_with_ac(input, "/affiliation set", affiliation_ac, TRUE, previous);
@@ -3457,7 +3442,7 @@ _role_autocomplete(ProfWin* window, const char* const input, gboolean previous)
         gboolean parse_result;
         Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
 
-        gchar** args = parse_args(input, 2, 3, &parse_result);
+        auto_gcharv gchar** args = parse_args(input, 2, 3, &parse_result);
 
         if ((strncmp(input, "/role", 5) == 0) && (parse_result == TRUE)) {
             GString* beginning = g_string_new("/role ");
@@ -3470,12 +3455,9 @@ _role_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             result = autocomplete_param_with_ac(input, beginning->str, nick_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (result) {
-                g_strfreev(args);
                 return result;
             }
         }
-
-        g_strfreev(args);
     }
 
     result = autocomplete_param_with_ac(input, "/role set", role_ac, TRUE, previous);
@@ -3589,7 +3571,7 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
     char* found = NULL;
     gboolean result = FALSE;
 
-    gchar** args = parse_args(input, 1, 9, &result);
+    auto_gcharv gchar** args = parse_args(input, 1, 9, &result);
 
     if (result) {
         gboolean space_at_end = g_str_has_suffix(input, " ");
@@ -3600,7 +3582,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3611,7 +3592,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3621,7 +3601,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3632,7 +3611,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3642,7 +3620,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3653,7 +3630,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3663,7 +3639,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3674,7 +3649,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3688,7 +3662,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3699,7 +3672,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3710,7 +3682,6 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3721,14 +3692,11 @@ _connect_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
     }
 
-    g_strfreev(args);
-
     found = autocomplete_param_with_func(input, "/connect", accounts_find_enabled, previous, NULL);
     if (found) {
         return found;
@@ -3757,7 +3725,7 @@ _join_autocomplete(ProfWin* window, const char* const input, gboolean previous)
     char* found = NULL;
     gboolean result = FALSE;
 
-    gchar** args = parse_args(input, 1, 5, &result);
+    auto_gcharv gchar** args = parse_args(input, 1, 5, &result);
 
     if (result) {
         gboolean space_at_end = g_str_has_suffix(input, " ");
@@ -3768,7 +3736,6 @@ _join_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3778,14 +3745,11 @@ _join_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
     }
 
-    g_strfreev(args);
-
     found = autocomplete_param_with_func(input, "/join", bookmark_find, previous, NULL);
 
     return found;
@@ -3877,7 +3841,7 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
     char* found = NULL;
     gboolean result = FALSE;
 
-    gchar** args = parse_args(input, 2, 4, &result);
+    auto_gcharv gchar** args = parse_args(input, 2, 4, &result);
     if (result && (strcmp(args[0], "set") == 0)) {
         gboolean space_at_end = g_str_has_suffix(input, " ");
         int num_args = g_strv_length(args);
@@ -3887,7 +3851,6 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, account_set_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3911,7 +3874,6 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, account_status_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3922,7 +3884,6 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3933,7 +3894,6 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, auth_property_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3944,7 +3904,6 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_func(input, beginning->str, _script_autocomplete_func, previous, NULL);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3966,7 +3925,6 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_ac(input, beginning->str, theme_load_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3978,7 +3936,6 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
             found = autocomplete_param_with_func(input, beginning->str, p_gpg_autocomplete_key, previous, NULL);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -3991,13 +3948,10 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou
         found = autocomplete_param_with_ac(input, beginning->str, account_clear_ac, TRUE, previous);
         g_string_free(beginning, TRUE);
         if (found) {
-            g_strfreev(args);
             return found;
         }
     }
 
-    g_strfreev(args);
-
     found = autocomplete_param_with_ac(input, "/account default", account_default_ac, TRUE, previous);
     if (found) {
         return found;
@@ -4054,7 +4008,7 @@ _rooms_autocomplete(ProfWin* window, const char* const input, gboolean previous)
     char* found = NULL;
     gboolean result = FALSE;
 
-    gchar** args = parse_args(input, 0, 4, &result);
+    auto_gcharv gchar** args = parse_args(input, 0, 4, &result);
 
     if (result) {
         gboolean space_at_end = g_str_has_suffix(input, " ");
@@ -4062,21 +4016,18 @@ _rooms_autocomplete(ProfWin* window, const char* const input, gboolean previous)
         if (num_args <= 1) {
             found = autocomplete_param_with_ac(input, "/rooms", rooms_all_ac, TRUE, previous);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
         if ((num_args == 1 && g_strcmp0(args[0], "service") == 0 && space_at_end) || (num_args == 2 && g_strcmp0(args[0], "service") == 0 && !space_at_end)) {
             found = autocomplete_param_with_func(input, "/rooms service", muc_confserver_find, previous, NULL);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
         if ((num_args == 1 && g_strcmp0(args[0], "cache") == 0 && space_at_end) || (num_args == 2 && g_strcmp0(args[0], "cache") == 0 && !space_at_end)) {
             found = autocomplete_param_with_ac(input, "/rooms cache", rooms_cache_ac, TRUE, previous);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -4086,7 +4037,6 @@ _rooms_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             found = autocomplete_param_with_ac(input, beginning->str, rooms_list_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
@@ -4096,18 +4046,14 @@ _rooms_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             found = autocomplete_param_with_func(input, beginning->str, muc_confserver_find, previous, NULL);
             g_string_free(beginning, TRUE);
             if (found) {
-                g_strfreev(args);
                 return found;
             }
         }
         if ((num_args >= 2) && g_strcmp0(args[0], "cache") == 0) {
-            g_strfreev(args);
             return NULL;
         }
     }
 
-    g_strfreev(args);
-
     return NULL;
 }
 
@@ -4374,7 +4320,7 @@ _url_autocomplete(ProfWin* window, const char* const input, gboolean previous)
         }
 
         gboolean arg_result;
-        gchar** args = parse_args(input, 1, 8, &arg_result);
+        auto_gcharv gchar** args = parse_args(input, 1, 8, &arg_result);
         gboolean space_at_end = g_str_has_suffix(input, " ");
         int num_args = g_strv_length(args);
 
@@ -4387,7 +4333,6 @@ _url_autocomplete(ProfWin* window, const char* const input, gboolean previous)
                 g_free(cmd);
             }
         }
-        g_strfreev(args);
     }
 
     return result;
@@ -4497,7 +4442,7 @@ _vcard_autocomplete(ProfWin* window, const char* const input, gboolean previous)
     char* result = NULL;
 
     gboolean parse_result = FALSE;
-    gchar** args = parse_args(input, 0, 7, &parse_result);
+    auto_gcharv gchar** args = parse_args(input, 0, 7, &parse_result);
 
     if (parse_result && (g_strcmp0(args[0], "set") == 0)) {
         gboolean space_at_end = g_str_has_suffix(input, " ");
@@ -4519,7 +4464,6 @@ _vcard_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             result = autocomplete_param_with_ac(input, beginning->str, vcard_set_param_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (result) {
-                g_strfreev(args);
                 return result;
             }
         } else if ((num_args == 3 && space_at_end && is_num && (g_strcmp0(args[2], "type") == 0)) || (num_args == 4 && !space_at_end && is_num && (g_strcmp0(args[2], "type") == 0))) {
@@ -4528,7 +4472,6 @@ _vcard_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             result = autocomplete_param_with_ac(input, beginning->str, vcard_address_type_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (result) {
-                g_strfreev(args);
                 return result;
             }
         } else if ((num_args == 3 && space_at_end && is_num && autocomplete_contains(vcard_togglable_param_ac, args[2])) || (num_args == 4 && !space_at_end && is_num && autocomplete_contains(vcard_togglable_param_ac, args[2]))) {
@@ -4537,7 +4480,6 @@ _vcard_autocomplete(ProfWin* window, const char* const input, gboolean previous)
             result = autocomplete_param_with_ac(input, beginning->str, vcard_toggle_ac, TRUE, previous);
             g_string_free(beginning, TRUE);
             if (result) {
-                g_strfreev(args);
                 return result;
             }
         } else {
diff --git a/src/common.c b/src/common.c
index 41628c4f..7888a1dc 100644
--- a/src/common.c
+++ b/src/common.c
@@ -79,6 +79,14 @@ auto_free_gchar(gchar** str)
 }
 
 void
+auto_free_gcharv(gchar*** args)
+{
+    if (args == NULL)
+        return;
+    g_strfreev(*args);
+}
+
+void
 auto_free_char(char** str)
 {
     if (str == NULL)
diff --git a/src/common.h b/src/common.h
index ade72cfa..359e313e 100644
--- a/src/common.h
+++ b/src/common.h
@@ -49,6 +49,8 @@
 
 void auto_free_gchar(gchar** str);
 #define auto_gchar __attribute__((__cleanup__(auto_free_gchar)))
+void auto_free_gcharv(gchar*** args);
+#define auto_gcharv __attribute__((__cleanup__(auto_free_gcharv)))
 void auto_free_char(char** str);
 #define auto_char __attribute__((__cleanup__(auto_free_char)))