X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Ffs-util.c;h=f6fb7cabc48a8c7ab198fe5fb252c62a096f9b8b;hb=c0e8baacdbcf4cee407eb0c50c6fbb7e4e089158;hp=05f10c86f827a9c9f86aa73794f8f014dddf6138;hpb=701d4cf38514d96ea0618807ac3b08a9e52c60cd;p=elogind.git diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 05f10c86f..f6fb7cabc 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -728,6 +728,8 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, return -errno; if (S_ISLNK(st.st_mode)) { + char *joined; + _cleanup_free_ char *destination = NULL; /* This is a symlink, in this case read the destination. But let's make sure we don't follow @@ -751,9 +753,6 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, if (fd < 0) return -errno; - free_and_replace(buffer, destination); - - todo = buffer; free(done); /* Note that we do not revalidate the root, we take it as is. */ @@ -765,19 +764,17 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags, return -ENOMEM; } - } else { - char *joined; + } - /* A relative destination. If so, this is what we'll prefix what's left to do with what - * we just read, and start the loop again, but remain in the current directory. */ + /* Prefix what's left to do with what we just read, and start the loop again, + * but remain in the current directory. */ - joined = strjoin("/", destination, todo); - if (!joined) - return -ENOMEM; + joined = strjoin("/", destination, todo); + if (!joined) + return -ENOMEM; - free(buffer); - todo = buffer = joined; - } + free(buffer); + todo = buffer = joined; continue; }