From 59db7fb35b260925abac7afe39ddd165deb87f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=20=28=D0=B4=D0=BE=D0=BC=D0=B0=29?= Date: Fri, 26 Apr 2013 23:50:54 +0600 Subject: [PATCH 1/2] dump_attrs: "NLA_F_NESTED" => nla_is_nested(nla) --- lib/msg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/msg.c b/lib/msg.c index dafee67..6478507 100644 --- a/lib/msg.c +++ b/lib/msg.c @@ -886,10 +886,10 @@ static void dump_attrs(FILE *ofd, struct nlattr *attrs, int attrlen, fprintf(ofd, " [ATTR PADDING] %d octets\n", alen); else fprintf(ofd, " [ATTR %02d%s] %d octets\n", nla_type(nla), - nla->nla_type & NLA_F_NESTED ? " NESTED" : "", + nla_is_nested(nla) ? " NESTED" : "", alen); - if (nla->nla_type & NLA_F_NESTED) + if (nla_is_nested(nla)) dump_attrs(ofd, nla_data(nla), alen, prefix+1); else dump_attr(ofd, nla, prefix); From 33396faca5d48a0318cdd85b4da2c3b247063781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA=20=28=D0=B4=D0=BE=D0=BC=D0=B0=29?= Date: Sun, 28 Apr 2013 00:35:37 +0600 Subject: [PATCH 2/2] Fix leak of cb if nl_socket_alloc_cb() failed to allocate socket - each *_get() should have corresponding *_put(). That rule was broken in nl_socket_alloc() - Also, check if cb is NULL in nl_socket_set_cb (calls BUG()) --- lib/socket.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/socket.c b/lib/socket.c index d3e636e..1ca7783 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -120,7 +120,7 @@ static struct nl_sock *__alloc_socket(struct nl_cb *cb) return NULL; sk->s_fd = -1; - sk->s_cb = cb; + sk->s_cb = nl_cb_get(cb); sk->s_local.nl_family = AF_NETLINK; sk->s_peer.nl_family = AF_NETLINK; sk->s_seq_expect = sk->s_seq_next = time(0); @@ -141,12 +141,18 @@ static struct nl_sock *__alloc_socket(struct nl_cb *cb) struct nl_sock *nl_socket_alloc(void) { struct nl_cb *cb; - + struct nl_sock *sk; + cb = nl_cb_alloc(default_cb); if (!cb) return NULL; - return __alloc_socket(cb); + /* will increment cb reference count on success */ + sk = __alloc_socket(cb); + + nl_cb_put(cb); + + return sk; } /** @@ -163,7 +169,7 @@ struct nl_sock *nl_socket_alloc_cb(struct nl_cb *cb) if (cb == NULL) BUG(); - return __alloc_socket(nl_cb_get(cb)); + return __alloc_socket(cb); } /** @@ -519,6 +525,9 @@ struct nl_cb *nl_socket_get_cb(const struct nl_sock *sk) void nl_socket_set_cb(struct nl_sock *sk, struct nl_cb *cb) { + if (cb == NULL) + BUG(); + nl_cb_put(sk->s_cb); sk->s_cb = nl_cb_get(cb); }