cli: fix crash in complete function

$ nmcli --complete-args connection import type non-existing-<TAB>

Leads to a double-free of out_to_free, as we call g_free(v) in
nm_meta_abstract_info_complete().

Also fix a memleak when skipping over non-matching values.

Fixes: afac7621ae
This commit is contained in:
Thomas Haller 2017-06-28 14:28:58 +02:00
parent 699492c1a5
commit 870f493853

View file

@ -295,15 +295,17 @@ nm_meta_abstract_info_complete (const NMMetaAbstractInfo *abstract_info,
char **v = *out_to_free;
for (i = 0, j = 0; v[i]; i++) {
if (strncmp (v[i], text, text_len) != 0)
if (strncmp (v[i], text, text_len) != 0) {
g_free (v[i]);
continue;
}
v[j++] = v[i];
}
if (j)
v[j++] = NULL;
else {
g_free (v);
v = NULL;
*out_to_free = v = NULL;
}
return (const char *const*) v;
} else {