fix broken memory when assigning fd.path variable

This commit is contained in:
2025-01-01 12:46:58 -06:00
parent 0dc5bb53c0
commit 00f838e3b4

View File

@@ -27,7 +27,7 @@ public:
try {
// Always convert to absolute path
fs::path new_root = fs::absolute(fs::weakly_canonical(_root));
fd.path = new_root.string().c_str();
fd.path = strdup(new_root.c_str());
// Create directory if it doesn't exist
if (!fs::exists(new_root)) {
@@ -55,7 +55,7 @@ public:
try {
// Always convert to absolute path
fs::path new_cwd = fs::weakly_canonical(_cwd);
fd.path = new_cwd.string().c_str();
fd.path = strdup(new_cwd.c_str());
// Create directory if it doesn't exist
if (!fs::exists(root / new_cwd)) {
@@ -131,7 +131,7 @@ public:
}
if (dir.empty() || dir == ".") {
fd.path = requested_path.c_str();
fd.path = strdup(requested_path.c_str());
return fd;
}
@@ -155,7 +155,7 @@ public:
// Update current working directory relative to root
cwd = "/" + rel_path.string();
fd.path = requested_path.string().c_str();
fd.path = strdup(requested_path.c_str());
} catch (const fs::filesystem_error& ex) {
logger->print(LOGLEVEL_ERROR, "Path fallback: %s", ex.what());
@@ -173,7 +173,7 @@ public:
return fd;
}
fd.path = resolved.string().c_str();
fd.path = strdup(resolved.c_str());
if (fs::exists(resolved)) {
fd.error = file_error{FilerStatusCodes::FileExists, "Directory Already Exists"};
@@ -196,7 +196,7 @@ public:
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
return fd;
}
fd.path = resolved.string().c_str();
fd.path = strdup(resolved.c_str());
if (!fs::exists(resolved)) {
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};
@@ -229,7 +229,7 @@ public:
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
return fd;
}
fd.path = resolved.c_str();
fd.path = strdup(resolved.c_str());
std::error_code err;
if (!fs::remove(resolved, err)) {
@@ -259,7 +259,7 @@ public:
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
return fd;
}
fd.path = resolved.string().c_str();
fd.path = strdup(resolved.c_str());
if (!fs::exists(resolved)) {
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};
@@ -296,7 +296,7 @@ public:
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
return fd;
}
fd.path = resolved.string().c_str();
fd.path = strdup(resolved.c_str());
std::ios_base::openmode omode = std::ios::out|std::ios::binary;
if (append) omode |= std::ios::app;
@@ -338,8 +338,8 @@ public:
// Perform the rename operation
std::filesystem::rename(src_path, dst_path);
fd.path = strdup(dst_path.c_str());
fd.error = {0, "OK"};
} catch (const std::filesystem::filesystem_error& e) {
fd.error = {FilerStatusCodes::AccessDenied, e.what()};
}
@@ -355,7 +355,7 @@ public:
fd.error = file_error{FilerStatusCodes::NoPermission, "Invalid Permissions"};
return fd;
}
fd.path = resolved.string().c_str();
fd.path = strdup(resolved.c_str());
if (!fs::exists(resolved)) {
fd.error = file_error{FilerStatusCodes::NotFound, "File Not Found"};