[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 12/26] qga: make split_list() return allocated strin
From: |
Michael Roth |
Subject: |
[Qemu-devel] [PATCH 12/26] qga: make split_list() return allocated strings |
Date: |
Tue, 1 Sep 2015 12:00:52 -0500 |
From: Marc-André Lureau <address@hidden>
In order to avoid any confusion, let's allocate new strings when
splitting.
Signed-off-by: Marc-André Lureau <address@hidden>
Reviewed-by: Denis V. Lunev <address@hidden>
Signed-off-by: Michael Roth <address@hidden>
---
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
- [Qemu-devel] [PATCH 11/26] qga: move string split in separate function, (continued)
- [Qemu-devel] [PATCH 11/26] qga: move string split in separate function, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 10/26] qga: use exit() when parsing options, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 09/26] qga: misc spelling, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 13/26] qga: rename 'path' to 'channel_path', Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 14/26] qga: copy argument strings, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 15/26] qga: move option parsing to separate function, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 17/26] qga: move agent run in a separate function, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 18/26] qga: free a bit more, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 16/26] qga: fill default options in main(), Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 01/26] qemu-ga: Add .msi files to .gitignore, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 12/26] qga: make split_list() return allocated strings,
Michael Roth <=
- [Qemu-devel] [PATCH 19/26] qga: add an optional qemu-ga.conf system configuration, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 23/26] configure: qemu-ga: move MSI installer probe after qga probe, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 20/26] qga: add --dump-conf option, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 22/26] qemu-ga: implement win32 guest-set-user-password, Michael Roth, 2015/09/01
- [Qemu-devel] [PATCH 21/26] qga: start a man page, Michael Roth, 2015/09/01
- Re: [Qemu-devel] [PULL 00/26] qemu-ga patch queue for 2015-09-01, Peter Maydell, 2015/09/01
- [Qemu-devel] [PATCH 24/26] configure: qemu-ga: explicitly enable qemu-ga MSI support when probed, Michael Roth, 2015/09/01