From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWqSv-0006sl-3p for qemu-devel@nongnu.org; Tue, 01 Sep 2015 14:39:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWqSr-0006Cb-1i for qemu-devel@nongnu.org; Tue, 01 Sep 2015 14:39:29 -0400 Received: from e17.ny.us.ibm.com ([129.33.205.207]:38116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWqSq-0006CI-U1 for qemu-devel@nongnu.org; Tue, 01 Sep 2015 14:39:24 -0400 Received: from /spool/local by e17.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 1 Sep 2015 14:39:24 -0400 Received: from b01cxnp22033.gho.pok.ibm.com (b01cxnp22033.gho.pok.ibm.com [9.57.198.23]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 7132A38C805C for ; Tue, 1 Sep 2015 14:39:21 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t81IdL0e54788192 for ; Tue, 1 Sep 2015 18:39:21 GMT Received: from d01av03.pok.ibm.com (localhost [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t81IdKvs028069 for ; Tue, 1 Sep 2015 14:39:21 -0400 From: Michael Roth Date: Tue, 1 Sep 2015 13:38:49 -0500 Message-Id: <1441132743-26228-13-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1441132743-26228-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1441132743-26228-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 12/26] qga: make split_list() return allocated strings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Michael Roth , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau In order to avoid any confusion, let's allocate new strings when splitting. Signed-off-by: Marc-André Lureau Reviewed-by: Denis V. Lunev Signed-off-by: Michael Roth --- qga/commands-posix.c | 6 +++--- qga/commands-win32.c | 4 ++-- qga/main.c | 22 +++++++++------------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 675f4b4..fc4fc72 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -2454,7 +2454,7 @@ GList *ga_command_blacklist_init(GList *blacklist) char **p = (char **)list; while (*p) { - blacklist = g_list_append(blacklist, *p++); + blacklist = g_list_append(blacklist, g_strdup(*p++)); } } #endif @@ -2468,13 +2468,13 @@ GList *ga_command_blacklist_init(GList *blacklist) char **p = (char **)list; while (*p) { - blacklist = g_list_append(blacklist, *p++); + blacklist = g_list_append(blacklist, g_strdup(*p++)); } } #endif #if !defined(CONFIG_FSTRIM) - blacklist = g_list_append(blacklist, (char *)"guest-fstrim"); + blacklist = g_list_append(blacklist, g_strdup("guest-fstrim")); #endif return blacklist; diff --git a/qga/commands-win32.c b/qga/commands-win32.c index a7822d5..1152c46 100644 --- a/qga/commands-win32.c +++ b/qga/commands-win32.c @@ -1233,7 +1233,7 @@ GList *ga_command_blacklist_init(GList *blacklist) char **p = (char **)list_unsupported; while (*p) { - blacklist = g_list_append(blacklist, *p++); + blacklist = g_list_append(blacklist, g_strdup(*p++)); } if (!vss_init(true)) { @@ -1244,7 +1244,7 @@ GList *ga_command_blacklist_init(GList *blacklist) p = (char **)list; while (*p) { - blacklist = g_list_append(blacklist, *p++); + blacklist = g_list_append(blacklist, g_strdup(*p++)); } } diff --git a/qga/main.c b/qga/main.c index e75022c..a7df6c8 100644 --- a/qga/main.c +++ b/qga/main.c @@ -921,22 +921,17 @@ static void ga_print_cmd(QmpCommand *cmd, void *opaque) printf("%s\n", qmp_command_name(cmd)); } -static GList *split_list(gchar *str, const gchar separator) +static GList *split_list(const gchar *str, const gchar *delim) { GList *list = NULL; - int i, j, len; + int i; + gchar **strv; - for (j = 0, i = 0, len = strlen(str); i < len; i++) { - if (str[i] == separator) { - str[i] = 0; - list = g_list_append(list, &str[j]); - j = i + 1; - } - } - - if (j < i) { - list = g_list_append(list, &str[j]); + strv = g_strsplit(str, delim, -1); + for (i = 0; strv[i]; i++) { + list = g_list_prepend(list, strv[i]); } + g_free(strv); return list; } @@ -1021,7 +1016,7 @@ int main(int argc, char **argv) qmp_for_each_command(ga_print_cmd, NULL); exit(EXIT_SUCCESS); } - blacklist = g_list_concat(blacklist, split_list(optarg, ',')); + blacklist = g_list_concat(blacklist, split_list(optarg, ",")); break; } #ifdef _WIN32 @@ -1201,6 +1196,7 @@ int main(int argc, char **argv) } #endif + g_list_free_full(ga_state->blacklist, g_free); ga_command_state_cleanup_all(ga_state->command_state); ga_channel_free(ga_state->channel); -- 1.9.1