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>
This commit is contained in:
parent
23b42894b3
commit
4bca81ceed
@ -2454,7 +2454,7 @@ GList *ga_command_blacklist_init(GList *blacklist)
|
|||||||
char **p = (char **)list;
|
char **p = (char **)list;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
blacklist = g_list_append(blacklist, *p++);
|
blacklist = g_list_append(blacklist, g_strdup(*p++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -2468,13 +2468,13 @@ GList *ga_command_blacklist_init(GList *blacklist)
|
|||||||
char **p = (char **)list;
|
char **p = (char **)list;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
blacklist = g_list_append(blacklist, *p++);
|
blacklist = g_list_append(blacklist, g_strdup(*p++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(CONFIG_FSTRIM)
|
#if !defined(CONFIG_FSTRIM)
|
||||||
blacklist = g_list_append(blacklist, (char *)"guest-fstrim");
|
blacklist = g_list_append(blacklist, g_strdup("guest-fstrim"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return blacklist;
|
return blacklist;
|
||||||
|
@ -1233,7 +1233,7 @@ GList *ga_command_blacklist_init(GList *blacklist)
|
|||||||
char **p = (char **)list_unsupported;
|
char **p = (char **)list_unsupported;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
blacklist = g_list_append(blacklist, *p++);
|
blacklist = g_list_append(blacklist, g_strdup(*p++));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!vss_init(true)) {
|
if (!vss_init(true)) {
|
||||||
@ -1244,7 +1244,7 @@ GList *ga_command_blacklist_init(GList *blacklist)
|
|||||||
p = (char **)list;
|
p = (char **)list;
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
blacklist = g_list_append(blacklist, *p++);
|
blacklist = g_list_append(blacklist, g_strdup(*p++));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
qga/main.c
22
qga/main.c
@ -921,22 +921,17 @@ static void ga_print_cmd(QmpCommand *cmd, void *opaque)
|
|||||||
printf("%s\n", qmp_command_name(cmd));
|
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;
|
GList *list = NULL;
|
||||||
int i, j, len;
|
int i;
|
||||||
|
gchar **strv;
|
||||||
|
|
||||||
for (j = 0, i = 0, len = strlen(str); i < len; i++) {
|
strv = g_strsplit(str, delim, -1);
|
||||||
if (str[i] == separator) {
|
for (i = 0; strv[i]; i++) {
|
||||||
str[i] = 0;
|
list = g_list_prepend(list, strv[i]);
|
||||||
list = g_list_append(list, &str[j]);
|
|
||||||
j = i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (j < i) {
|
|
||||||
list = g_list_append(list, &str[j]);
|
|
||||||
}
|
}
|
||||||
|
g_free(strv);
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
@ -1021,7 +1016,7 @@ int main(int argc, char **argv)
|
|||||||
qmp_for_each_command(ga_print_cmd, NULL);
|
qmp_for_each_command(ga_print_cmd, NULL);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
blacklist = g_list_concat(blacklist, split_list(optarg, ','));
|
blacklist = g_list_concat(blacklist, split_list(optarg, ","));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -1201,6 +1196,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
g_list_free_full(ga_state->blacklist, g_free);
|
||||||
ga_command_state_cleanup_all(ga_state->command_state);
|
ga_command_state_cleanup_all(ga_state->command_state);
|
||||||
ga_channel_free(ga_state->channel);
|
ga_channel_free(ga_state->channel);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user