try fix memory leak in StorageHDFS

This commit is contained in:
Andrey Zvonov 2023-12-14 13:01:47 +01:00
parent b1325450e9
commit 7d7aea9826

View File

@ -75,6 +75,13 @@ namespace ErrorCodes
}
namespace
{
struct HDFSFileInfoDeleter
{
/// Can have only one entry (see hdfsGetPathInfo())
void operator()(hdfsFileInfo * info) { hdfsFreeFileInfo(info, 1); }
};
using HDFSFileInfoPtr = std::unique_ptr<hdfsFileInfo, HDFSFileInfoDeleter>;
/* Recursive directory listing with matched paths as a result.
* Have the same method in StorageFile.
*/
@ -90,13 +97,12 @@ namespace
if (first_glob_pos == std::string::npos)
{
const String path = fs::path(path_for_ls + for_match.substr(1)).lexically_normal();
HDFSFileInfo ls;
ls.file_info = hdfsGetPathInfo(fs.get(), path.c_str());
if (ls.file_info != nullptr) // NOLINT
HDFSFileInfoPtr hdfs_info(hdfsGetPathInfo(fs.get(), path.c_str()));
if (hdfs_info) // NOLINT
{
result.push_back(StorageHDFS::PathWithInfo{
String(path),
StorageHDFS::PathInfo{ls.file_info->mLastMod, static_cast<size_t>(ls.file_info->mSize)}});
StorageHDFS::PathInfo{hdfs_info->mLastMod, static_cast<size_t>(hdfs_info->mSize)}});
}
return result;
}
@ -184,13 +190,6 @@ namespace
}
return res;
}
struct HDFSFileInfoDeleter
{
/// Can have only one entry (see hdfsGetPathInfo())
void operator()(hdfsFileInfo * info) { hdfsFreeFileInfo(info, 1); }
};
using HDFSFileInfoPtr = std::unique_ptr<hdfsFileInfo, HDFSFileInfoDeleter>;
}
StorageHDFS::StorageHDFS(