Skip to content

Commit d59e308

Browse files
authored
[Bugfix] update block dir permission & double-free fix (#603)
* [bugfix] double-free while create reader failed * [bugfix] update permission of block dir to 774
1 parent 1260f9f commit d59e308

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

ucm/store/pcstore/cc/domain/file/posix_file.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,17 @@ PosixFile::~PosixFile() { this->Close(); }
3737

3838
Status PosixFile::MkDir()
3939
{
40-
constexpr auto permission = (S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IROTH);
40+
constexpr auto permission = (S_IRWXU | S_IRWXG | S_IROTH);
4141
auto ret = mkdir(this->Path().c_str(), permission);
4242
auto eno = errno;
4343
if (ret != 0) {
44-
if (eno == EEXIST) {
45-
return Status::DuplicateKey();
46-
} else {
47-
UC_ERROR("Failed to create directory, path: {}, errcode: {}, errno: {}.", this->Path(),
48-
ret, eno);
49-
return Status::OsApiError();
50-
}
44+
if (eno == EEXIST) { return Status::DuplicateKey(); }
45+
UC_ERROR("Failed({},{}) to create dir({}).", ret, eno, this->Path());
46+
return Status::OsApiError();
5147
}
48+
ret = chmod(this->Path().c_str(), permission);
49+
eno = errno;
50+
if (ret != 0) { UC_WARN("Failed({},{}) to set perm on dir({}).", ret, eno, this->Path()); }
5251
return Status::OK();
5352
}
5453

ucm/store/pcstore/cc/domain/trans/share_buffer.cc

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,11 @@ std::shared_ptr<ShareBuffer::Reader> ShareBuffer::MakeLocalReader(const std::str
314314
UC_ERROR("Failed to make buffer({}) on host.", blockSize_);
315315
return nullptr;
316316
}
317-
Reader* reader = nullptr;
318317
try {
319-
reader = new Reader{block, path, blockSize_, ioDirect_, false, addr.get()};
320-
return std::shared_ptr<Reader>(reader,
321-
[addr = std::move(addr)](Reader* reader) { delete reader; });
318+
return std::shared_ptr<Reader>(
319+
new Reader{block, path, blockSize_, ioDirect_, false, addr.get()},
320+
[addr = std::move(addr)](Reader* reader) { delete reader; });
322321
} catch (const std::exception& e) {
323-
if (reader) { delete reader; }
324322
UC_ERROR("Failed({}) to create reader.", e.what());
325323
return nullptr;
326324
}
@@ -331,17 +329,15 @@ std::shared_ptr<ShareBuffer::Reader> ShareBuffer::MakeSharedReader(const std::st
331329
size_t position)
332330
{
333331
void* addr = this->BlockAt(position);
334-
Reader* reader = nullptr;
335332
try {
336-
reader = new Reader{block, path, blockSize_, ioDirect_, true, addr};
337-
return std::shared_ptr<Reader>(reader, [this, position](Reader* reader) {
338-
delete reader;
339-
this->ReleaseBlock(position);
340-
});
341-
} catch (...) {
333+
return std::shared_ptr<Reader>(new Reader{block, path, blockSize_, ioDirect_, true, addr},
334+
[this, position](Reader* reader) {
335+
delete reader;
336+
this->ReleaseBlock(position);
337+
});
338+
} catch (const std::exception& e) {
342339
this->ReleaseBlock(position);
343-
if (reader) { delete reader; }
344-
UC_ERROR("Failed to create reader.");
340+
UC_ERROR("Failed({}) to create reader.", e.what());
345341
return nullptr;
346342
}
347343
}

0 commit comments

Comments
 (0)