summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2012-11-16 00:20:18 +0100
committerThomas Graf <tgraf@suug.ch>2012-11-16 00:29:58 +0100
commitcb82c2a5451a52e7365957a2325258af1b179aee (patch)
tree2f166ab92205d745534500d525fb6e07ab3213c9
parent2b3912a320ef74b31d84380d91ec036dbf1b9f52 (diff)
downloadlibnl-cb82c2a5451a52e7365957a2325258af1b179aee.tar.gz
use safe cache lookup variants internally
Signed-off-by: Thomas Graf <tgraf@suug.ch>
-rw-r--r--lib/cache.c6
-rw-r--r--lib/cache_mngr.c3
-rw-r--r--lib/msg.c20
-rw-r--r--lib/object.c6
4 files changed, 24 insertions, 11 deletions
diff --git a/lib/cache.c b/lib/cache.c
index 257a41b..36566e0 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -266,11 +266,13 @@ int nl_cache_alloc_name(const char *kind, struct nl_cache **result)
struct nl_cache_ops *ops;
struct nl_cache *cache;
- ops = nl_cache_ops_lookup(kind);
+ ops = nl_cache_ops_lookup_safe(kind);
if (!ops)
return -NLE_NOCACHE;
- if (!(cache = nl_cache_alloc(ops)))
+ cache = nl_cache_alloc(ops);
+ nl_cache_ops_put(ops);
+ if (!cache)
return -NLE_NOMEM;
*result = cache;
diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c
index 63cc0d3..bf92d11 100644
--- a/lib/cache_mngr.c
+++ b/lib/cache_mngr.c
@@ -314,11 +314,12 @@ int nl_cache_mngr_add(struct nl_cache_mngr *mngr, const char *name,
struct nl_cache *cache;
int err;
- ops = nl_cache_ops_lookup(name);
+ ops = nl_cache_ops_lookup_safe(name);
if (!ops)
return -NLE_NOCACHE;
cache = nl_cache_alloc(ops);
+ nl_cache_ops_put(ops);
if (!cache)
return -NLE_NOMEM;
diff --git a/lib/msg.c b/lib/msg.c
index 0adc091..23c137d 100644
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -733,14 +733,18 @@ int nl_msg_parse(struct nl_msg *msg, void (*cb)(struct nl_object *, void *),
.cb = cb,
.arg = arg,
};
+ int err;
- ops = nl_cache_ops_associate(nlmsg_get_proto(msg),
- nlmsg_hdr(msg)->nlmsg_type);
+ ops = nl_cache_ops_associate_safe(nlmsg_get_proto(msg),
+ nlmsg_hdr(msg)->nlmsg_type);
if (ops == NULL)
return -NLE_MSGTYPE_NOSUPPORT;
p.pp_arg = &x;
- return nl_cache_parse(ops, NULL, nlmsg_hdr(msg), &p);
+ err = nl_cache_parse(ops, NULL, nlmsg_hdr(msg), &p);
+ nl_cache_ops_put(ops);
+
+ return err;
}
/** @} */
@@ -801,13 +805,14 @@ static void print_hdr(FILE *ofd, struct nl_msg *msg)
fprintf(ofd, " .nlmsg_len = %d\n", nlh->nlmsg_len);
- ops = nl_cache_ops_associate(nlmsg_get_proto(msg), nlh->nlmsg_type);
+ ops = nl_cache_ops_associate_safe(nlmsg_get_proto(msg), nlh->nlmsg_type);
if (ops) {
mt = nl_msgtype_lookup(ops, nlh->nlmsg_type);
if (!mt)
BUG();
snprintf(buf, sizeof(buf), "%s::%s", ops->co_name, mt->mt_name);
+ nl_cache_ops_put(ops);
} else
nl_nlmsgtype2str(nlh->nlmsg_type, buf, sizeof(buf));
@@ -888,8 +893,8 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
int payloadlen = nlmsg_len(hdr);
int attrlen = 0;
- ops = nl_cache_ops_associate(nlmsg_get_proto(msg),
- hdr->nlmsg_type);
+ ops = nl_cache_ops_associate_safe(nlmsg_get_proto(msg),
+ hdr->nlmsg_type);
if (ops) {
attrlen = nlmsg_attrlen(hdr, ops->co_hdrsize);
payloadlen -= attrlen;
@@ -906,6 +911,9 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
attrlen = nlmsg_attrlen(hdr, ops->co_hdrsize);
dump_attrs(ofd, attrs, attrlen, 0);
}
+
+ if (ops)
+ nl_cache_ops_put(ops);
}
fprintf(ofd,
diff --git a/lib/object.c b/lib/object.c
index 024062e..806bae6 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -85,11 +85,13 @@ int nl_object_alloc_name(const char *kind, struct nl_object **result)
{
struct nl_cache_ops *ops;
- ops = nl_cache_ops_lookup(kind);
+ ops = nl_cache_ops_lookup_safe(kind);
if (!ops)
return -NLE_OPNOTSUPP;
- if (!(*result = nl_object_alloc(ops->co_obj_ops)))
+ *result = nl_object_alloc(ops->co_obj_ops);
+ nl_cache_ops_put(ops);
+ if (!*result)
return -NLE_NOMEM;
return 0;