From 831e98688a2fceddc3d78ac0207793f41cb3c445 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Tue, 27 Aug 2024 16:44:02 +0200 Subject: [PATCH] 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 --- lib/cache.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/cache.c b/lib/cache.c index bae641de..f133d6cb 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;