summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJonas Gorski <jonas.gorski@bisdn.de>2024-08-27 14:44:02 (GMT)
committerThomas Haller <thaller@redhat.com>2024-09-12 07:24:20 (GMT)
commit831e98688a2fceddc3d78ac0207793f41cb3c445 (patch)
treee359d1480c0aa339a908d04394efd5781e7fa41e /lib
parent4b9daa6d7d05a232b5b52aeeb4b76d472a6d007d (diff)
downloadlibnl-831e98688a2fceddc3d78ac0207793f41cb3c445.zip
libnl-831e98688a2fceddc3d78ac0207793f41cb3c445.tar.gz
libnl-831e98688a2fceddc3d78ac0207793f41cb3c445.tar.bz2
cache: use the new _nl_auto_nl_object helper
Use the new _nl_auto_nl_object helper for cache where appropriate. Make sure to initialze *old to NULL in cache_include() as we do not initialize it in the error path for unknown actions. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/cache.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/cache.c b/lib/cache.c
index bae641d..f133d6c 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -714,17 +714,14 @@ static int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache,
static int pickup_checkdup_cb(struct nl_object *c, struct nl_parser_param *p)
{
struct nl_cache *cache = (struct nl_cache *)p->pp_arg;
- struct nl_object *old;
+ _nl_auto_nl_object struct nl_object *old = NULL;
old = nl_cache_search(cache, c);
if (old) {
- if (nl_object_update(old, c) == 0) {
- nl_object_put(old);
+ if (nl_object_update(old, c) == 0)
return 0;
- }
nl_cache_remove(old);
- nl_object_put(old);
}
return nl_cache_add(cache, c);
@@ -788,8 +785,8 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
struct nl_msgtype *type, change_func_t cb,
change_func_v2_t cb_v2, void *data)
{
- struct nl_object *old;
- struct nl_object *clone = NULL;
+ _nl_auto_nl_object struct nl_object *old = NULL;
+ _nl_auto_nl_object struct nl_object *clone = NULL;
uint64_t diff = 0;
switch (type->mt_act) {
@@ -813,11 +810,8 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
nl_object_put(clone);
} else if (cb)
cb(cache, old, NL_ACT_CHANGE, data);
- nl_object_put(old);
return 0;
}
- nl_object_put(clone);
-
nl_cache_remove(old);
if (type->mt_act == NL_ACT_DEL) {
if (cb_v2)
@@ -825,7 +819,6 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
data);
else if (cb)
cb(cache, old, NL_ACT_DEL, data);
- nl_object_put(old);
}
}
@@ -847,7 +840,6 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
} else if (diff && cb)
cb(cache, obj, NL_ACT_CHANGE, data);
- nl_object_put(old);
}
}
break;