]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
chcon: fix memory leak in error path
authorPádraig Brady <P@draigBrady.com>
Sat, 8 Nov 2025 10:32:14 +0000 (10:32 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 8 Nov 2025 10:41:48 +0000 (10:41 +0000)
* src/chcon.c (change_file_context): If compute_context_from_mask fails,
free the previously allocated file_context.
Fixes https://bugs.gnu.org/79780

src/chcon.c

index f118820ccd9c528f2edf5fe89a10a1b6dee03f02..5f13c7d7572ae2afda25ae25be8313ede729a4b8 100644 (file)
@@ -168,7 +168,10 @@ change_file_context (int fd, char const *file)
         }
 
       if (compute_context_from_mask (file_context, &context))
-        return 1;
+        {
+          freecon (file_context);
+          return 1;
+        }
 
       context_string = context_str (context);
     }