Преглед изворни кода

LibFileSystem: Replace PATH_MAX usage with heap allocation

Sergey Bugaev пре 1 година
родитељ
комит
ae10d085ba
1 измењених фајлова са 3 додато и 2 уклоњено
  1. 3 2
      Userland/Libraries/LibFileSystem/FileSystem.cpp

+ 3 - 2
Userland/Libraries/LibFileSystem/FileSystem.cpp

@@ -6,6 +6,7 @@
  */
  */
 
 
 #include <AK/LexicalPath.h>
 #include <AK/LexicalPath.h>
+#include <AK/ScopeGuard.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/DirIterator.h>
 #include <LibCore/System.h>
 #include <LibCore/System.h>
 #include <LibFileSystem/FileSystem.h>
 #include <LibFileSystem/FileSystem.h>
@@ -47,9 +48,9 @@ ErrorOr<String> real_path(StringView path)
     if (path.is_null())
     if (path.is_null())
         return Error::from_errno(ENOENT);
         return Error::from_errno(ENOENT);
 
 
-    char buffer[PATH_MAX];
     DeprecatedString dep_path = path;
     DeprecatedString dep_path = path;
-    auto* real_path = realpath(dep_path.characters(), buffer);
+    char* real_path = realpath(dep_path.characters(), nullptr);
+    ScopeGuard free_path = [real_path]() { free(real_path); };
 
 
     if (!real_path)
     if (!real_path)
         return Error::from_syscall("realpath"sv, -errno);
         return Error::from_syscall("realpath"sv, -errno);