From 340f05ba42b4e4ad89250f4ab947d6b944b3eca1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 22 Jan 2022 16:50:37 +0100 Subject: platform: use proper g_free() function for netlink receive buffer In the past, nl_recv() was libnl3 code and thus used malloc()/realloc() to allocate the buffer. That meant, we should free the buffer with libc's free() function instead of glib's g_free(). That is what nm_auto_free is for. Nowadays, nl_recv() is forked and glib-ified, and uses the glib wrappers to allocate the buffer. Thus the buffer should also be freed with g_free() (and gs_free). In practice there is no difference, because glib's allocation directly uses libc's malloc/free. This is purely a matter of style. --- src/libnm-platform/nm-linux-platform.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/libnm-platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index ed67afe665..c596d3ef8a 100644 --- a/src/libnm-platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -9021,21 +9021,22 @@ event_handler(int fd, GIOCondition io_condition, gpointer user_data) static int event_handler_recvmsgs(NMPlatform *platform, gboolean handle_events) { - NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); - struct nl_sock *sk = priv->nlh; - int n; - int err = 0; - gboolean multipart = 0; - gboolean interrupted = FALSE; - struct nlmsghdr *hdr; - WaitForNlResponseResult seq_result; - struct sockaddr_nl nla = {0}; - struct ucred creds; - gboolean creds_has; - nm_auto_free unsigned char *buf = NULL; + NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE(platform); + struct nl_sock *sk = priv->nlh; + int n; + int err = 0; + gboolean multipart = 0; + gboolean interrupted = FALSE; + struct nlmsghdr *hdr; + WaitForNlResponseResult seq_result; + struct sockaddr_nl nla = {0}; + struct ucred creds; + gboolean creds_has; + gs_free unsigned char *buf = NULL; continue_reading: - nm_clear_pointer(&buf, free); + nm_clear_g_free(&buf); + n = nl_recv(sk, &nla, &buf, &creds, &creds_has); if (n <= 0) { -- cgit v1.2.1