]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
perf(dracut-install): convert_abs_rel: don't allocate target parent realpath
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Thu, 28 Apr 2022 22:08:41 +0000 (00:08 +0200)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Fri, 24 Jun 2022 20:27:08 +0000 (20:27 +0000)
src/install/dracut-install.c

index 3ab34209c87e8514ce9fb807ccd4e0842213ba15..49785aa0a284bdd1755d2fde541113b61f058d5a 100644 (file)
@@ -164,7 +164,7 @@ static char *convert_abs_rel(const char *from, const char *target)
         /* we use the 4*MAXPATHLEN, which should not overrun */
         char buf[MAXPATHLEN * 4];
         _cleanup_free_ char *realtarget = NULL, *realfrom = NULL, *from_dir_p = NULL;
-        _cleanup_free_ char *target_dir_p = NULL, *realpath_p = NULL;
+        _cleanup_free_ char *target_dir_p = NULL;
         size_t level = 0, fromlevel = 0, targetlevel = 0;
         int l;
         size_t i, rl, dirlen;
@@ -187,16 +187,14 @@ static char *convert_abs_rel(const char *from, const char *target)
         target_dir_p = strndup(target, dirlen);
         if (!target_dir_p)
                 return strdup(from + strlen(destrootdir));
-
-        realpath_p = realpath(target_dir_p, NULL);
-        if (realpath_p == NULL) {
+        if (realpath(target_dir_p, buf) == NULL) {
                 log_warning("convert_abs_rel(): target '%s' directory has no realpath: %m", target);
                 return strdup(from + strlen(destrootdir));
         }
 
         for (i = dirlen + 1; target[i] == '/'; ++i)
                 ;
-        _asprintf(&realtarget, "%s/%s", realpath_p, &target[i]);
+        _asprintf(&realtarget, "%s/%s", buf, target + i);
 
         /* now calculate the relative path from <from> to <target> and
            store it in <buf>