return -1;
}
- // Merge excluded list with subnets
- r = loc_network_list_merge(subnets, excluded);
+ // Merge subnets onto the stack
+ r = loc_network_list_merge(enumerator->stack, subnets);
if (r) {
loc_network_list_unref(subnets);
loc_network_list_unref(excluded);
return r;
}
- // We no longer need the excluded list
- loc_network_list_unref(excluded);
-
- // Replace network with the first one
- loc_network_unref(*network);
+ // Push excluded list onto the stack
+ r = loc_network_list_merge(enumerator->stack, excluded);
+ if (r) {
+ loc_network_list_unref(subnets);
+ loc_network_list_unref(excluded);
- *network = loc_network_list_pop_first(subnets);
+ return r;
+ }
- // Push the rest onto the stack
- loc_network_list_merge(enumerator->stack, subnets);
loc_network_list_unref(subnets);
+ loc_network_list_unref(excluded);
+
+ // Replace network with the first one from the stack
+ loc_network_unref(*network);
+ *network = loc_network_list_pop_first(enumerator->stack);
return 0;
}