libnl/lib
Thomas Haller d65c32a720 link: fix memory leaks due to repeated calls to .io_alloc()
All the io_alloc() implementation unconditionally allocated
new memory, thus leaking memory if called more then once.
Fix io_alloc() implementations not to allocate new memory
if not needed.

This happens for example in link_msg_parser() which first
calls rtnl_link_set_type():

    #0  macvlan_alloc (link=0x609d50) at route/link/macvlan.c:56
    #1  0x00007ffff7b99a78 in rtnl_link_set_type (link=link@entry=0x609d50, type=type@entry=0x609a94 "macvlan") at route/link.c:2233
    #2  0x00007ffff7b99c28 in link_msg_parser (ops=<optimized out>, who=<optimized out>, n=<optimized out>, pp=0x7fffffffd870) at route/link.c:547
    #3  0x00007ffff7dea109 in nl_cache_parse (ops=0x7ffff7dd8600 <rtnl_link_ops>, who=0x603338, nlh=0x6098a0, params=0x7fffffffd870) at cache.c:914
    #4  0x00007ffff7dea15b in update_msg_parser (msg=<optimized out>, arg=<optimized out>) at cache.c:668
    #5  0x00007ffff7def7bf in nl_cb_call (msg=<optimized out>, type=<optimized out>, cb=<optimized out>) at ../include/netlink-private/netlink.h:142
    #6  recvmsgs (cb=0x6057a0, sk=0x6034c0) at nl.c:952
    #7  nl_recvmsgs_report (sk=sk@entry=0x6034c0, cb=cb@entry=0x6057a0) at nl.c:1003
    #8  0x00007ffff7defb79 in nl_recvmsgs (sk=sk@entry=0x6034c0, cb=cb@entry=0x6057a0) at nl.c:1027
    #9  0x00007ffff7de9668 in __cache_pickup (sk=0x6034c0, cache=0x603510, param=param@entry=0x7fffffffd870) at cache.c:701
    #10 0x00007ffff7dea08d in nl_cache_pickup (sk=<optimized out>, cache=<optimized out>) at cache.c:753
    #11 0x0000000000400d56 in main ()

and later ops->io_parse():

    #0  macvlan_alloc (link=0x609d50) at route/link/macvlan.c:56
    #1  0x00007ffff7baae9d in macvlan_parse (link=0x609d50, data=<optimized out>, xstats=<optimized out>) at route/link/macvlan.c:79
    #2  0x00007ffff7b99c80 in link_msg_parser (ops=<optimized out>, who=<optimized out>, n=<optimized out>, pp=0x7fffffffd870) at route/link.c:567
    #3  0x00007ffff7dea109 in nl_cache_parse (ops=0x7ffff7dd8600 <rtnl_link_ops>, who=0x603338, nlh=0x6098a0, params=0x7fffffffd870) at cache.c:914
    #4  0x00007ffff7dea15b in update_msg_parser (msg=<optimized out>, arg=<optimized out>) at cache.c:668
    #5  0x00007ffff7def7bf in nl_cb_call (msg=<optimized out>, type=<optimized out>, cb=<optimized out>) at ../include/netlink-private/netlink.h:142
    #6  recvmsgs (cb=0x6057a0, sk=0x6034c0) at nl.c:952
    #7  nl_recvmsgs_report (sk=sk@entry=0x6034c0, cb=cb@entry=0x6057a0) at nl.c:1003
    #8  0x00007ffff7defb79 in nl_recvmsgs (sk=sk@entry=0x6034c0, cb=cb@entry=0x6057a0) at nl.c:1027
    #9  0x00007ffff7de9668 in __cache_pickup (sk=0x6034c0, cache=0x603510, param=param@entry=0x7fffffffd870) at cache.c:701
    #10 0x00007ffff7dea08d in nl_cache_pickup (sk=<optimized out>, cache=<optimized out>) at cache.c:753
    #11 0x0000000000400d56 in main ()

https://github.com/thom311/libnl/issues/59

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-10-12 19:35:46 +02:00
..
cli qdisc: avoid calling strstr() with a NULL haystack 2014-08-27 12:56:34 +02:00
fib_lookup Use thread-safe strerror_r() instead of strerror() 2013-02-28 13:07:04 +01:00
genl style: require comma after __ADD() macro 2014-07-27 10:57:31 +02:00
idiag idiag: fix a typo in idiagnl_req_set_ifindex() 2014-09-24 07:50:25 +02:00
netfilter nf: Remove unused function htonll() 2014-08-26 13:09:20 +02:00
route link: fix memory leaks due to repeated calls to .io_alloc() 2014-10-12 19:35:46 +02:00
xfrm xfrm: fix xfrm_sa_msg_parser() to return the value from the callback 2014-08-27 13:00:46 +02:00
.gitignore Added lex.yy.c to .gitignore 2012-08-30 03:19:04 +06:00
addr.c style: require comma after __ADD() macro 2014-07-27 10:57:31 +02:00
attr.c attr: nla_get_u64() should return 0 if the attribute does not fully contain 64 bit 2014-06-25 12:37:58 +02:00
cache.c cache: fix crash in nl_cache_dump_filter() when omitting the params argument 2014-06-10 21:45:52 +02:00
cache_mngr.c cache_mngr: Fix assignment of error code in nl_cache_mngr_alloc() 2014-06-17 17:33:26 +02:00
cache_mngt.c cache_mngt: Make __nl_cache_ops_lookup() static, it was never declared 2014-07-27 11:04:07 +02:00
data.c Move private header files to <netlink-private/*> 2013-01-24 13:51:24 +01:00
error.c Move private header files to <netlink-private/*> 2013-01-24 13:51:24 +01:00
handlers.c Remove pointless N < 0 checks 2014-08-26 14:12:52 +02:00
hash.c Hash: Properly prefix hash functions 2012-11-10 10:22:26 +01:00
hashtable.c Move private header files to <netlink-private/*> 2013-01-24 13:51:24 +01:00
Makefile.am build: move copy of linux headers to private directory 2014-09-24 16:00:31 +02:00
msg.c style: require comma after __ADD() macro 2014-07-27 10:57:31 +02:00
nl.c lib/socket: retry generate local port in nl_connect on ADDRINUSE 2014-05-06 14:34:58 +02:00
object.c lib: reorder free() after printf("%p") statements 2014-06-10 21:45:51 +02:00
socket.c socket: Be correct, time(2) takes a pointer, not an integer 2014-07-27 11:04:07 +02:00
utils.c style: require comma after __ADD() macro 2014-07-27 10:57:31 +02:00
version.c Run-time version information is now available 2012-08-30 03:19:04 +06:00