Introduce `smartlist_add_strdup()` function
There are many places in the code (and the tests) where we do the following pattern:
smartlist_add(sl, tor_strdup(str))
Some examples:
routerparse.c: smartlist_add(ns->package_lines, tor_strdup(t->args[0])));
routerparse.c: smartlist_add(ns->known_flags, tor_strdup(tok->args[i]));
routerparse.c: smartlist_add(ns->net_params, tor_strdup(tok->args[i]));
routerparse.c: smartlist_add(ns->weight_params, tor_strdup(tok->args[i]));
routerparse.c: smartlist_add(md->family, tor_strdup(tok->args[i]));
routerset.c: smartlist_add(set->country_names, tor_strdup("??"));
routerset.c: smartlist_add(set->list, tor_strdup("{??}"));
routerset.c: smartlist_add(set->country_names, tor_strdup("a1"));
routerset.c: smartlist_add(set->list, tor_strdup("{a1}"));
One could imagine a smartlist_add_strdup()
function that does this for the developer, and can be used in places where this pattern is used repeatedly.
It might simplify logic in a few places, or maybe it will confuse peole who grep for tor_strdup
searching for allocations.
If people think this is worth doing, let's do it!