about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSteffen Jaeckel <jaeckel-floss@eyet-services.de>2023-03-31 12:30:12 +0200
committerSteffen Jaeckel <jaeckel-floss@eyet-services.de>2023-04-04 10:58:52 +0200
commitaf6f468cb738ec77dc2cac82d5c91b5847279346 (patch)
tree4108789253dee89873b71061c09b0d23f4fdff90
parent36fd4faa4f9aaf2c32126097b73500ee55712f66 (diff)
downloadprofani-tty-af6f468cb738ec77dc2cac82d5c91b5847279346.tar.gz
fix memory leak
`found` was leaked before

This was somehow missed in e9aaba938b4f1b62b5f9018583a82ed7e7180977

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
-rw-r--r--src/tools/autocomplete.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c
index 227b79e0..27532081 100644
--- a/src/tools/autocomplete.c
+++ b/src/tools/autocomplete.c
@@ -314,11 +314,8 @@ autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote,
 static char*
 _autocomplete_param_common(const char* const input, char* command, autocomplete_func func, Autocomplete ac, gboolean quote, gboolean previous, void* context)
 {
-    char* command_cpy;
-    char* result = NULL;
     int len;
-
-    command_cpy = g_strdup_printf("%s ", command);
+    auto_char char* command_cpy = g_strdup_printf("%s ", command);
     if (!command_cpy) {
         return NULL;
     }
@@ -327,8 +324,11 @@ _autocomplete_param_common(const char* const input, char* command, autocomplete_
 
     if (strncmp(input, command_cpy, len) == 0) {
         int inp_len = strlen(input);
-        char prefix[inp_len];
-        char* found;
+        auto_char char* found = NULL;
+        auto_char char* prefix = malloc(inp_len + 1);
+        if (!prefix) {
+            return NULL;
+        }
 
         for (int i = len; i < inp_len; i++) {
             prefix[i - len] = input[i];
@@ -343,12 +343,11 @@ _autocomplete_param_common(const char* const input, char* command, autocomplete_
         }
 
         if (found) {
-            result = g_strdup_printf("%s%s", command_cpy, found);
+            return g_strdup_printf("%s%s", command_cpy, found);
         }
     }
-    free(command_cpy);
 
-    return result;
+    return NULL;
 }
 
 char*