Use g_slist_prepend as we don't care about the order. Check for list == NULL instead of iterating the list to see if it is empty. Move ctx allocation down to prevent leak in case of failure.