]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup-util: fix memory leak on error
authorLuca Boccassi <luca.boccassi@gmail.com>
Thu, 21 Nov 2024 00:53:20 +0000 (00:53 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 21 Nov 2024 05:02:34 +0000 (14:02 +0900)
CID#1565824

Follow-up for f6793bbcf0e3f0a6daa77add96183b88d5ec2117

src/basic/cgroup-util.c

index 5370090f0071b0292f8352ed56158e6508f4d58f..8b1e051d56264ecd04168fe6580b72de79de1e0e 100644 (file)
@@ -799,7 +799,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
                                 continue;
                 }
 
-                char *path = strdup(e + 1);
+                _cleanup_free_ char *path = strdup(e + 1);
                 if (!path)
                         return -ENOMEM;
 
@@ -812,7 +812,7 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **ret_path) {
                 if (e)
                         *e = 0;
 
-                *ret_path = path;
+                *ret_path = TAKE_PTR(path);
                 return 0;
         }
 }