The following commit has been merged in the master branch:
commit 3b2b9aea518f3e3a562a57a9d7caa2623b4876ff
Author: Guillem Jover <[email protected]>
Date: Tue Sep 13 05:17:34 2011 +0200
u-a: Add ref counting support to struct alternative
This will allow to properly free an alternative map which contains
duplicated references to the same alternative struct.
diff --git a/utils/update-alternatives.c b/utils/update-alternatives.c
index 205672e..2107241 100644
--- a/utils/update-alternatives.c
+++ b/utils/update-alternatives.c
@@ -719,6 +719,7 @@ struct alternative {
struct commit_operation *commit_ops;
+ int ref_count;
bool modified;
};
@@ -751,10 +752,23 @@ alternative_new(const char *name)
alt->choices = NULL;
alt->commit_ops = NULL;
alt->modified = false;
+ alt->ref_count = 1;
return alt;
}
+static inline void
+alternative_ref(struct alternative *a)
+{
+ a->ref_count++;
+}
+
+static inline bool
+alternative_unref(struct alternative *a)
+{
+ return --a->ref_count == 0;
+}
+
static void
alternative_choices_free(struct alternative *a)
{
@@ -802,6 +816,9 @@ alternative_reset(struct alternative *alt)
static void
alternative_free(struct alternative *alt)
{
+ if (!alternative_unref(alt))
+ return;
+
alternative_reset(alt);
free(alt->master_name);
free(alt);
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]