Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add auto cleanup helper for nl_object and use it #402

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/nl-aux-core/nl-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ void nl_cache_mngr_free(struct nl_cache_mngr *mngr);
_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_cache_mngr *, _nl_auto_nl_cache_mngr_fcn,
nl_cache_mngr_free);

struct nl_object;
void nl_object_put(struct nl_object *);
#define _nl_auto_nl_object _nl_auto(_nl_auto_nl_object_fcn)
_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_object *, _nl_auto_nl_object_fcn,
nl_object_put);

struct nl_addr *nl_addr_build(int, const void *, size_t);

static inline struct nl_addr *_nl_addr_build(int family, const void *buf)
Expand Down
16 changes: 4 additions & 12 deletions lib/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
thom311 marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down Expand Up @@ -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) {
Expand All @@ -813,19 +810,15 @@ 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)
cb_v2(cache, old, NULL, 0, NL_ACT_DEL,
data);
else if (cb)
cb(cache, old, NL_ACT_DEL, data);
nl_object_put(old);
}
}

Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions lib/xfrm/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ static int xfrm_sa_update_cache (struct nl_cache *cache, struct nl_object *obj,
change_func_t change_cb, change_func_v2_t change_cb_v2,
void *data)
{
struct nl_object* old_sa;
_nl_auto_nl_object struct nl_object* old_sa = NULL;
struct xfrmnl_sa* sa = (struct xfrmnl_sa*)obj;

if (nl_object_get_msgtype (obj) == XFRM_MSG_EXPIRE)
Expand Down Expand Up @@ -1064,7 +1064,6 @@ static int xfrm_sa_update_cache (struct nl_cache *cache, struct nl_object *obj,
} else if (change_cb)
change_cb(cache, obj, NL_ACT_CHANGE, data);
}
nl_object_put (old_sa);
}
}
else
Expand All @@ -1075,7 +1074,6 @@ static int xfrm_sa_update_cache (struct nl_cache *cache, struct nl_object *obj,
change_cb_v2(cache, obj, NULL, 0, NL_ACT_DEL, data);
else if (change_cb)
change_cb (cache, obj, NL_ACT_DEL, data);
nl_object_put (old_sa);
}

/* Done handling expire message */
Expand Down
Loading