about summary refs log tree commit diff stats
path: root/src/tools/parser.c
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-07-23 09:42:43 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-07-23 09:42:43 +0200
commitade0ff589d145b494d0e211645ea00332371d9aa (patch)
treec9175fd7428ea42ef88744361bac6daf524d8ee1 /src/tools/parser.c
parent8c0c5cb28ce74d4eb66a3161dadaa07068b15383 (diff)
downloadprofani-tty-ade0ff589d145b494d0e211645ea00332371d9aa.tar.gz
parser.c: Use glib
We use malloc() to allcoate memory for the arguments.
But later on in cmd_funcs.c we use g_strfreev() to free it.
Let's use g_malloc() to allocate instead.

Second change is to use g_malloc() and g_free() for a gchar.
Diffstat (limited to 'src/tools/parser.c')
-rw-r--r--src/tools/parser.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/tools/parser.c b/src/tools/parser.c
index beb61383..364dd436 100644
--- a/src/tools/parser.c
+++ b/src/tools/parser.c
@@ -138,14 +138,14 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb
         // if min allowed is 0 and 0 found, return empty char* array
     } else if (min == 0 && num == 0) {
         g_slist_free_full(tokens, free);
-        gchar** args = malloc((num + 1) * sizeof(*args));
+        gchar** args = g_malloc((num + 1) * sizeof(*args));
         args[0] = NULL;
         *result = TRUE;
         return args;
 
         // otherwise return args array
     } else {
-        gchar** args = malloc((num + 1) * sizeof(*args));
+        gchar** args = g_malloc((num + 1) * sizeof(*args));
         GSList* token = tokens;
         token = g_slist_next(token);
         int arg_count = 0;
@@ -298,11 +298,11 @@ get_start(const char* const string, int tokens)
         gunichar curr_uni = g_utf8_get_char(curr_ch);
 
         if (num_tokens < tokens) {
-            gchar* uni_char = malloc(7);
+            gchar* uni_char = g_malloc(7);
             int len = g_unichar_to_utf8(curr_uni, uni_char);
             uni_char[len] = '\0';
             g_string_append(result, uni_char);
-            free(uni_char);
+            g_free(uni_char);
         }
         if (curr_uni == ' ') {
             if (!in_quotes) {