This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=3a751b9d11d38492e762b8f8debdbf1bcf1e22de commit 3a751b9d11d38492e762b8f8debdbf1bcf1e22de (HEAD -> main) Author: Guillem Jover <[email protected]> AuthorDate: Mon Nov 21 23:27:05 2022 +0100 u-a: Switch point at which we increment alternative refcount Instead of incrementing the refcount from the call sites, do that from within the alternative_map_add() function which is the one taking the reference. And unref on the functions that get their local functions get out of scope. Which is way more correct, and removes the anti-pattern of having to recall to increment the refcount before calling any subsequent alternative_map_add() after the second one. --- utils/update-alternatives.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c index 1bc63ff7b..684518d21 100644 --- a/utils/update-alternatives.c +++ b/utils/update-alternatives.c @@ -2265,6 +2265,8 @@ static void alternative_map_add(struct alternative_map *am, const char *key, struct alternative *a) { + alternative_ref(a); + if (am->key == NULL) { am->key = key; am->item = a; @@ -2292,6 +2294,8 @@ alternative_map_load_names(struct alternative_map *alt_map_obj) continue; } alternative_map_add(alt_map_obj, a_new->master_name, a_new); + + alternative_unref(a_new); } altdb_free_namelist(table, count); } @@ -2313,14 +2317,13 @@ alternative_map_load_tree(struct alternative_map *alt_map_links, continue; } alternative_map_add(alt_map_links, a_new->master_link, a_new); - alternative_ref(a_new); alternative_map_add(alt_map_parent, a_new->master_name, a_new); for (sl = a_new->slaves; sl; sl = sl->next) { - alternative_ref(a_new); alternative_map_add(alt_map_links, sl->link, a_new); - alternative_ref(a_new); alternative_map_add(alt_map_parent, sl->name, a_new); } + + alternative_unref(a_new); } altdb_free_namelist(table, count); } -- Dpkg.Org's dpkg

