summary refs log tree commit diff
path: root/src/platform/nm-linux-platform.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/nm-linux-platform.c')
-rw-r--r--src/platform/nm-linux-platform.c64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index d222527d..305ae52e 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -1,21 +1,8 @@
-/* nm-linux-platform.c - Linux kernel & udev network configuration layer
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+// SPDX-License-Identifier: GPL-2.0+
+/*
  * Copyright (C) 2012 - 2018 Red Hat, Inc.
  */
+
 #include "nm-default.h"
 
 #include "nm-linux-platform.h"
@@ -868,14 +855,19 @@ _lookup_cached_link (const NMPCache *cache,
 static char *
 _linktype_read_devtype (int dirfd)
 {
-	char *contents = NULL;
+	gs_free char *contents = NULL;
 	char *cont, *end;
 
 	nm_assert (dirfd >= 0);
 
-	if (nm_utils_file_get_contents (dirfd, "uevent", 1*1024*1024,
-	                                NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE,
-	                                &contents, NULL, NULL) < 0)
+	if (!nm_utils_file_get_contents (dirfd,
+	                                 "uevent",
+	                                 1*1024*1024,
+	                                 NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE,
+	                                 &contents,
+	                                 NULL,
+	                                 NULL,
+	                                 NULL))
 		return NULL;
 	for (cont = contents; cont; cont = end) {
 		end = strpbrk (cont, "\r\n");
@@ -884,10 +876,9 @@ _linktype_read_devtype (int dirfd)
 		if (strncmp (cont, DEVTYPE_PREFIX, NM_STRLEN (DEVTYPE_PREFIX)) == 0) {
 			cont += NM_STRLEN (DEVTYPE_PREFIX);
 			memmove (contents, cont, strlen (cont) + 1);
-			return contents;
+			return g_steal_pointer (&contents);
 		}
 	}
-	g_free (contents);
 	return NULL;
 }
 
@@ -4398,12 +4389,17 @@ static void
 _log_dbg_sysctl_set_impl (NMPlatform *platform, const char *pathid, int dirfd, const char *path, const char *value)
 {
 	GError *error = NULL;
-	char *contents;
+	gs_free char *contents = NULL;
 	gs_free char *value_escaped = g_strescape (value, NULL);
 
-	if (nm_utils_file_get_contents (dirfd, path, 1*1024*1024,
-	                                NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE,
-	                                &contents, NULL, &error) < 0) {
+	if (!nm_utils_file_get_contents (dirfd,
+	                                 path,
+	                                 1*1024*1024,
+	                                 NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE,
+	                                 &contents,
+	                                 NULL,
+	                                 NULL,
+	                                 &error)) {
 		_LOGD ("sysctl: setting '%s' to '%s' (current value cannot be read: %s)", pathid ?: path, value_escaped, error->message);
 		g_clear_error (&error);
 		return;
@@ -4417,7 +4413,6 @@ _log_dbg_sysctl_set_impl (NMPlatform *platform, const char *pathid, int dirfd, c
 
 		_LOGD ("sysctl: setting '%s' to '%s' (current value is '%s')", pathid ?: path, value_escaped, contents_escaped);
 	}
-	g_free (contents);
 }
 
 #define _log_dbg_sysctl_set(platform, pathid, dirfd, path, value) \
@@ -4833,7 +4828,7 @@ sysctl_get (NMPlatform *platform, const char *pathid, int dirfd, const char *pat
 {
 	nm_auto_pop_netns NMPNetns *netns = NULL;
 	GError *error = NULL;
-	char *contents;
+	gs_free char *contents = NULL;
 
 	ASSERT_SYSCTL_ARGS (pathid, dirfd, path);
 
@@ -4845,9 +4840,14 @@ sysctl_get (NMPlatform *platform, const char *pathid, int dirfd, const char *pat
 		pathid = path;
 	}
 
-	if (nm_utils_file_get_contents (dirfd, path, 1*1024*1024,
-	                                NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE,
-	                                &contents, NULL, &error) < 0) {
+	if (!nm_utils_file_get_contents (dirfd,
+	                                 path,
+	                                 1*1024*1024,
+	                                 NM_UTILS_FILE_GET_CONTENTS_FLAG_NONE,
+	                                 &contents,
+	                                 NULL,
+	                                 NULL,
+	                                 &error)) {
 		NMLogLevel log_level = LOGL_ERR;
 		int errsv = EBUSY;
 
@@ -4871,7 +4871,7 @@ sysctl_get (NMPlatform *platform, const char *pathid, int dirfd, const char *pat
 	_log_dbg_sysctl_get (platform, pathid, contents);
 
 	/* errno is left undefined (as we don't return NULL). */
-	return contents;
+	return g_steal_pointer (&contents);
 }
 
 /*****************************************************************************/