diff options
author | Thomas Graf <tgraf@suug.ch> | 2012-11-16 00:20:18 +0100 |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2012-11-16 00:29:58 +0100 |
commit | cb82c2a5451a52e7365957a2325258af1b179aee (patch) | |
tree | 2f166ab92205d745534500d525fb6e07ab3213c9 /lib/msg.c | |
parent | 2b3912a320ef74b31d84380d91ec036dbf1b9f52 (diff) | |
download | libnl-cb82c2a5451a52e7365957a2325258af1b179aee.tar.gz |
use safe cache lookup variants internally
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Diffstat (limited to 'lib/msg.c')
-rw-r--r-- | lib/msg.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -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, |