From 870f4938535d260212a8667246c660019f03d202 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 28 Jun 2017 14:28:58 +0200 Subject: [PATCH] cli: fix crash in complete function $ nmcli --complete-args connection import type non-existing- 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: afac7621ae3b306701fa388e31f57b082a5b1510 --- clients/common/nm-meta-setting-access.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clients/common/nm-meta-setting-access.c b/clients/common/nm-meta-setting-access.c index f6038e1f1b..47869f95c6 100644 --- a/clients/common/nm-meta-setting-access.c +++ b/clients/common/nm-meta-setting-access.c @@ -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 {