diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2015-08-27 01:34:50 +0200 |
---|---|---|
committer | Michael Roth <mdroth@linux.vnet.ibm.com> | 2015-09-01 11:07:10 -0500 |
commit | 4bca81ceedb59397f6082777f6ed4b39d456be85 (patch) | |
tree | 675ba43edd7da179ff0e3ae15748cc4b2975fb1f /qga/main.c | |
parent | 23b42894b389eccb45ab66da3a3e77d3a8cfc2b6 (diff) |
qga: make split_list() return allocated strings
In order to avoid any confusion, let's allocate new strings when
splitting.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Diffstat (limited to 'qga/main.c')
-rw-r--r-- | qga/main.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/qga/main.c b/qga/main.c index e75022c44f..a7df6c83b1 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); |