diff options
author | Thomas Haller <thaller@redhat.com> | 2016-02-16 14:14:58 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-02-16 14:14:58 +0100 |
commit | 433d4fed6ac8f30161d20c2f192019eb44e7a77c (patch) | |
tree | 4bf7a3aa6c4bc702dab7b47be1d81747eb12fa6c | |
parent | ad45d232fee8157baadb799f3867ddec95e2ef91 (diff) | |
parent | 3d759b1f11110216749fbd4893e3e63594a8d70d (diff) | |
download | NetworkManager-433d4fed6ac8f30161d20c2f192019eb44e7a77c.tar.gz |
platform: merge branch 'th/platform-recvmsgs-fixes-bgo761959'
https://bugzilla.gnome.org/show_bug.cgi?id=761959
-rw-r--r-- | shared/nm-default.h | 2 | ||||
-rw-r--r-- | shared/nm-macros-internal.h | 10 | ||||
-rw-r--r-- | src/platform/nm-linux-platform.c | 40 |
3 files changed, 24 insertions, 28 deletions
diff --git a/shared/nm-default.h b/shared/nm-default.h index f1fcb845e4..72b74a5493 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -41,6 +41,8 @@ /* always include these headers for our internal source files. */ +#include <stdlib.h> + #include "nm-glib.h" #include "nm-version.h" #include "gsystem-local-alloc.h" diff --git a/shared/nm-macros-internal.h b/shared/nm-macros-internal.h index 63f513847a..4d802746ba 100644 --- a/shared/nm-macros-internal.h +++ b/shared/nm-macros-internal.h @@ -22,7 +22,15 @@ #ifndef __NM_MACROS_INTERNAL_H__ #define __NM_MACROS_INTERNAL_H__ -#include "nm-default.h" +/********************************************************/ + +/** + * nm_auto_free: + * + * Call free() on a variable location when it goes out of scope. + */ +#define nm_auto_free __attribute__ ((cleanup(_nm_auto_free_impl))) +GS_DEFINE_CLEANUP_FUNCTION(void*, _nm_auto_free_impl, free) /********************************************************/ diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 4c3ba361ce..f442f88b6a 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -5556,8 +5556,7 @@ event_handler_recvmsgs (NMPlatform *platform, gboolean handle_events) { NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); struct nl_sock *sk = priv->nlh; - int n, err = 0, multipart = 0, interrupted = 0, nrecv = 0; - unsigned char *buf = NULL; + int n, err = 0, multipart = 0, interrupted = 0; struct nlmsghdr *hdr; WaitForNlResponseResult seq_result; @@ -5567,10 +5566,12 @@ event_handler_recvmsgs (NMPlatform *platform, gboolean handle_events) initialize the variable. Thomas Graf. */ struct sockaddr_nl nla = {0}; - struct nl_msg *msg = NULL; - struct ucred *creds = NULL; + nm_auto_free struct ucred *creds = NULL; + nm_auto_free unsigned char *buf = NULL; continue_reading: + g_clear_pointer (&buf, free); + g_clear_pointer (&creds, free); errno = 0; n = nl_recv (sk, &nla, &buf, &creds); @@ -5600,9 +5601,9 @@ continue_reading: hdr = (struct nlmsghdr *) buf; while (nlmsg_ok (hdr, n)) { + nm_auto_nlmsg struct nl_msg *msg = NULL; gboolean abort_parsing = FALSE; - nlmsg_free (msg); msg = nlmsg_convert (hdr); if (!msg) { err = -NLE_NOMEM; @@ -5611,13 +5612,13 @@ continue_reading: nlmsg_set_proto (msg, NETLINK_ROUTE); nlmsg_set_src (msg, &nla); - nrecv++; if (!creds || creds->pid) { if (creds) - _LOGD ("netlink: recvmsg: received non-kernel message (pid %d)", creds->pid); + _LOGT ("netlink: recvmsg: received non-kernel message (pid %d)", creds->pid); else - _LOGD ("netlink: recvmsg: received message without credentials"); + _LOGT ("netlink: recvmsg: received message without credentials"); + err = 0; goto stop; } @@ -5697,19 +5698,13 @@ continue_reading: } event_seq_check (platform, msg, seq_result); - err = 0; - hdr = nlmsg_next (hdr, &n); if (abort_parsing) - goto out; - } + goto stop; - nlmsg_free (msg); - free (buf); - free (creds); - buf = NULL; - msg = NULL; - creds = NULL; + err = 0; + hdr = nlmsg_next (hdr, &n); + } if (multipart) { /* Multipart message not yet complete, continue reading */ @@ -5722,18 +5717,9 @@ stop: * Repeat reading. */ goto continue_reading; } - err = 0; out: - nlmsg_free (msg); - free (buf); - free (creds); - if (interrupted) err = -NLE_DUMP_INTR; - - if (!err) - err = nrecv; - return err; } |