]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ss: use freecon() instead of free() when appropriate
authorAndrea Claudi <aclaudi@redhat.com>
Fri, 28 Jan 2022 10:53:58 +0000 (11:53 +0100)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 31 Jan 2022 22:37:25 +0000 (14:37 -0800)
According to SELinux API, when resources are allocated using getpidcon()
of getfilecon(), they should be freed using freecon().

This commit makes ss use freecon() where appropriate, defining a stub
function executing a free() useful when iproute2 is compiled without
SELinux support.

Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
misc/ss.c

index b39f63fe3b17b390ae5fa56438708656f7a334b9..f7d369142d938ab50f5271ef8dd7f93347022d74 100644 (file)
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -97,6 +97,11 @@ static int security_get_initial_context(char *name,  char **context)
        *context = NULL;
        return -1;
 }
+
+static void freecon(char *context)
+{
+       free(context);
+}
 #endif
 
 int preferred_family = AF_UNSPEC;
@@ -618,7 +623,7 @@ static void user_ent_hash_build(void)
                snprintf(name + nameoff, sizeof(name) - nameoff, "%d/fd/", pid);
                pos = strlen(name);
                if ((dir1 = opendir(name)) == NULL) {
-                       free(pid_context);
+                       freecon(pid_context);
                        continue;
                }
 
@@ -667,9 +672,9 @@ static void user_ent_hash_build(void)
                        }
                        user_ent_add(ino, p, pid, fd,
                                        pid_context, sock_context);
-                       free(sock_context);
+                       freecon(sock_context);
                }
-               free(pid_context);
+               freecon(pid_context);
                closedir(dir1);
        }
        closedir(dir);
@@ -4725,7 +4730,7 @@ static int netlink_show_one(struct filter *f,
                        getpidcon(pid, &pid_context);
 
                out(" proc_ctx=%s", pid_context ? : "unavailable");
-               free(pid_context);
+               freecon(pid_context);
        }
 
        if (show_details) {