summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-01-22 16:50:37 +0100
committerThomas Haller <thaller@redhat.com>2022-02-03 13:07:35 +0100
commit340f05ba42b4e4ad89250f4ab947d6b944b3eca1 (patch)
treec6b97102dc2586289e3768185557fd484462f7bd
parent5153810bd64d2e5f75990a6919134b4948de89d8 (diff)
downloadNetworkManager-340f05ba42b4e4ad89250f4ab947d6b944b3eca1.tar.gz
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.
-rw-r--r--src/libnm-platform/nm-linux-platform.c27
1 files 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) {