diff --git a/src/core/queries.c b/src/core/queries.c index 2468256d..6e5dd0a9 100644 --- a/src/core/queries.c +++ b/src/core/queries.c @@ -47,15 +47,16 @@ void query_init(QUERY_REC *query, int automatic) g_return_if_fail(query->name != NULL); queries = g_slist_append(queries, query); - if (query->server != NULL) { - query->server->queries = - g_slist_append(query->server->queries, query); - } MODULE_DATA_INIT(query); query->type = module_get_uniq_id_str("WINDOW ITEM TYPE", "QUERY"); - if (query->server_tag != NULL) + if (query->server_tag != NULL) { query->server = server_find_tag(query->server_tag); + if (query->server != NULL) { + query->server->queries = + g_slist_append(query->server->queries, query); + } + } signal_emit("query created", 2, query, GINT_TO_POINTER(automatic)); } @@ -141,6 +142,13 @@ void query_change_server(QUERY_REC *query, SERVER_REC *server) { g_return_if_fail(IS_QUERY(query)); + if (query->server != NULL) { + query->server->queries = + g_slist_remove(query->server->queries, query); + } + if (server != NULL) + server->queries = g_slist_append(server->queries, query); + query->server = server; signal_emit("query server changed", 1, query); } diff --git a/src/core/servers.c b/src/core/servers.c index 4550ce7f..ac0f5bef 100644 --- a/src/core/servers.c +++ b/src/core/servers.c @@ -302,8 +302,8 @@ static int server_remove_channels(SERVER_REC *server) found = TRUE; } - for (tmp = server->queries; tmp != NULL; tmp = tmp->next) - query_change_server(tmp->data, NULL); + while (server->queries != NULL) + query_change_server(server->queries->data, NULL); g_slist_free(server->channels); g_slist_free(server->queries);