udev: fix memleak
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 21 Dec 2020 06:28:19 +0000 (15:28 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 2 Feb 2021 13:52:53 +0000 (14:52 +0100)
Fixes #18039.

(cherry picked from commit 9df1e11e31588c5df39aa7efed05414273f93f69)

src/udev/udev-node.c

index 2cc78c9e2f4294d0d1b91c1364671d55182f182c..b8b93eeb7afcd3dada98cfd748f91fbec6f0dfbe 100644 (file)
@@ -194,7 +194,7 @@ static int link_find_prioritized(sd_device *dev, bool add, const char *stackdir,
 
 /* manage "stack of names" with possibly specified device priorities */
 static int link_update(sd_device *dev, const char *slink, bool add) {
-        _cleanup_free_ char *target = NULL, *filename = NULL, *dirname = NULL;
+        _cleanup_free_ char *filename = NULL, *dirname = NULL;
         char name_enc[PATH_MAX];
         const char *id_filename;
         int i, r, retries;
@@ -237,6 +237,7 @@ static int link_update(sd_device *dev, const char *slink, bool add) {
         retries = sd_device_get_is_initialized(dev) > 0 ? LINK_UPDATE_MAX_RETRIES : 1;
 
         for (i = 0; i < retries; i++) {
+                _cleanup_free_ char *target = NULL;
                 struct stat st1 = {}, st2 = {};
 
                 r = stat(dirname, &st1);