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.
This commit is contained in:
Thomas Haller 2022-01-22 16:50:37 +01:00
parent 5153810bd6
commit 340f05ba42
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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) {