platform: simplify event_handler_recvmsgs() by using cleanup attribute
This commit is contained in:
@@ -5557,7 +5557,6 @@ event_handler_recvmsgs (NMPlatform *platform, gboolean handle_events)
|
|||||||
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
|
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
|
||||||
struct nl_sock *sk = priv->nlh;
|
struct nl_sock *sk = priv->nlh;
|
||||||
int n, err = 0, multipart = 0, interrupted = 0, nrecv = 0;
|
int n, err = 0, multipart = 0, interrupted = 0, nrecv = 0;
|
||||||
unsigned char *buf = NULL;
|
|
||||||
struct nlmsghdr *hdr;
|
struct nlmsghdr *hdr;
|
||||||
WaitForNlResponseResult seq_result;
|
WaitForNlResponseResult seq_result;
|
||||||
|
|
||||||
@@ -5567,10 +5566,12 @@ event_handler_recvmsgs (NMPlatform *platform, gboolean handle_events)
|
|||||||
initialize the variable. Thomas Graf.
|
initialize the variable. Thomas Graf.
|
||||||
*/
|
*/
|
||||||
struct sockaddr_nl nla = {0};
|
struct sockaddr_nl nla = {0};
|
||||||
struct nl_msg *msg = NULL;
|
nm_auto_free struct ucred *creds = NULL;
|
||||||
struct ucred *creds = NULL;
|
nm_auto_free unsigned char *buf = NULL;
|
||||||
|
|
||||||
continue_reading:
|
continue_reading:
|
||||||
|
g_clear_pointer (&buf, free);
|
||||||
|
g_clear_pointer (&creds, free);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
n = nl_recv (sk, &nla, &buf, &creds);
|
n = nl_recv (sk, &nla, &buf, &creds);
|
||||||
|
|
||||||
@@ -5600,9 +5601,9 @@ continue_reading:
|
|||||||
|
|
||||||
hdr = (struct nlmsghdr *) buf;
|
hdr = (struct nlmsghdr *) buf;
|
||||||
while (nlmsg_ok (hdr, n)) {
|
while (nlmsg_ok (hdr, n)) {
|
||||||
|
nm_auto_nlmsg struct nl_msg *msg = NULL;
|
||||||
gboolean abort_parsing = FALSE;
|
gboolean abort_parsing = FALSE;
|
||||||
|
|
||||||
nlmsg_free (msg);
|
|
||||||
msg = nlmsg_convert (hdr);
|
msg = nlmsg_convert (hdr);
|
||||||
if (!msg) {
|
if (!msg) {
|
||||||
err = -NLE_NOMEM;
|
err = -NLE_NOMEM;
|
||||||
@@ -5704,13 +5705,6 @@ continue_reading:
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlmsg_free (msg);
|
|
||||||
free (buf);
|
|
||||||
free (creds);
|
|
||||||
buf = NULL;
|
|
||||||
msg = NULL;
|
|
||||||
creds = NULL;
|
|
||||||
|
|
||||||
if (multipart) {
|
if (multipart) {
|
||||||
/* Multipart message not yet complete, continue reading */
|
/* Multipart message not yet complete, continue reading */
|
||||||
goto continue_reading;
|
goto continue_reading;
|
||||||
@@ -5724,10 +5718,6 @@ stop:
|
|||||||
}
|
}
|
||||||
err = 0;
|
err = 0;
|
||||||
out:
|
out:
|
||||||
nlmsg_free (msg);
|
|
||||||
free (buf);
|
|
||||||
free (creds);
|
|
||||||
|
|
||||||
if (interrupted)
|
if (interrupted)
|
||||||
err = -NLE_DUMP_INTR;
|
err = -NLE_DUMP_INTR;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user