Skip to content

Commit 831e986

Browse files
KanjiMonsterthom311
authored andcommitted
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 <[email protected]>
1 parent 4b9daa6 commit 831e986

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/cache.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -714,17 +714,14 @@ static int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache,
714714
static int pickup_checkdup_cb(struct nl_object *c, struct nl_parser_param *p)
715715
{
716716
struct nl_cache *cache = (struct nl_cache *)p->pp_arg;
717-
struct nl_object *old;
717+
_nl_auto_nl_object struct nl_object *old = NULL;
718718

719719
old = nl_cache_search(cache, c);
720720
if (old) {
721-
if (nl_object_update(old, c) == 0) {
722-
nl_object_put(old);
721+
if (nl_object_update(old, c) == 0)
723722
return 0;
724-
}
725723

726724
nl_cache_remove(old);
727-
nl_object_put(old);
728725
}
729726

730727
return nl_cache_add(cache, c);
@@ -788,8 +785,8 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
788785
struct nl_msgtype *type, change_func_t cb,
789786
change_func_v2_t cb_v2, void *data)
790787
{
791-
struct nl_object *old;
792-
struct nl_object *clone = NULL;
788+
_nl_auto_nl_object struct nl_object *old = NULL;
789+
_nl_auto_nl_object struct nl_object *clone = NULL;
793790
uint64_t diff = 0;
794791

795792
switch (type->mt_act) {
@@ -813,19 +810,15 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
813810
nl_object_put(clone);
814811
} else if (cb)
815812
cb(cache, old, NL_ACT_CHANGE, data);
816-
nl_object_put(old);
817813
return 0;
818814
}
819-
nl_object_put(clone);
820-
821815
nl_cache_remove(old);
822816
if (type->mt_act == NL_ACT_DEL) {
823817
if (cb_v2)
824818
cb_v2(cache, old, NULL, 0, NL_ACT_DEL,
825819
data);
826820
else if (cb)
827821
cb(cache, old, NL_ACT_DEL, data);
828-
nl_object_put(old);
829822
}
830823
}
831824

@@ -847,7 +840,6 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
847840
} else if (diff && cb)
848841
cb(cache, obj, NL_ACT_CHANGE, data);
849842

850-
nl_object_put(old);
851843
}
852844
}
853845
break;

0 commit comments

Comments
 (0)