1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

fix memory leak

`found` was leaked before

This was somehow missed in e9aaba938b

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2023-03-31 12:30:12 +02:00
parent 36fd4faa4f
commit af6f468cb7

View File

@ -314,11 +314,8 @@ autocomplete_complete(Autocomplete ac, const gchar* search_str, gboolean quote,
static char* static char*
_autocomplete_param_common(const char* const input, char* command, autocomplete_func func, Autocomplete ac, gboolean quote, gboolean previous, void* context) _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; int len;
auto_char char* command_cpy = g_strdup_printf("%s ", command);
command_cpy = g_strdup_printf("%s ", command);
if (!command_cpy) { if (!command_cpy) {
return NULL; return NULL;
} }
@ -327,8 +324,11 @@ _autocomplete_param_common(const char* const input, char* command, autocomplete_
if (strncmp(input, command_cpy, len) == 0) { if (strncmp(input, command_cpy, len) == 0) {
int inp_len = strlen(input); int inp_len = strlen(input);
char prefix[inp_len]; auto_char char* found = NULL;
char* found; auto_char char* prefix = malloc(inp_len + 1);
if (!prefix) {
return NULL;
}
for (int i = len; i < inp_len; i++) { for (int i = len; i < inp_len; i++) {
prefix[i - len] = input[i]; prefix[i - len] = input[i];
@ -343,12 +343,11 @@ _autocomplete_param_common(const char* const input, char* command, autocomplete_
} }
if (found) { 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* char*