summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/install.c6
-rw-r--r--src/shared/set.c7
-rw-r--r--src/shared/set.h1
3 files changed, 10 insertions, 4 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 959de04810..b22019d7b5 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -178,11 +178,9 @@ static int mark_symlink_for_removal(
path_kill_slashes(n);
- r = set_put(*remove_symlinks_to, n);
- if (r < 0) {
- free(n);
+ r = set_consume(*remove_symlinks_to, n);
+ if (r < 0)
return r == -EEXIST ? 0 : r;
- }
return 0;
}
diff --git a/src/shared/set.c b/src/shared/set.c
index 5f83c50839..c338dc3a44 100644
--- a/src/shared/set.c
+++ b/src/shared/set.c
@@ -49,6 +49,13 @@ int set_put(Set *s, void *value) {
return hashmap_put(MAKE_HASHMAP(s), value, value);
}
+int set_consume(Set *s, void *value) {
+ int r = set_put(s, value);
+ if (r < 0)
+ free(value);
+ return r;
+}
+
int set_replace(Set *s, void *value) {
return hashmap_replace(MAKE_HASHMAP(s), value, value);
}
diff --git a/src/shared/set.h b/src/shared/set.h
index 8864f7b34e..e5d46e9a8f 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -46,6 +46,7 @@ Set* set_copy(Set *s);
int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func);
int set_put(Set *s, void *value);
+int set_consume(Set *s, void *value);
int set_replace(Set *s, void *value);
void *set_get(Set *s, void *value);
bool set_contains(Set *s, void *value);