Skip to content

Commit 9b92914

Browse files
authored
[Issue #527] Fix the bug that iovecs might free twice (#528)
1 parent 4c53d6b commit 9b92914

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

cpp/pixels-reader/pixels-common/lib/physical/natives/DirectUringRandomAccessFile.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,23 @@ void DirectUringRandomAccessFile::Initialize() {
6767
}
6868

6969
void DirectUringRandomAccessFile::Reset() {
70-
// Important! Because sometimes ring is nullptr here.
71-
// For example, two threads A and B share the same global state. If A finish all files while B just starts,
72-
// B would execute Reset function from InitLocal. If we don't set this 'if' branch, ring would be double freed.
73-
if(ring != nullptr) {
70+
// Important! Because sometimes ring is nullptr here.
71+
// For example, two threads A and B share the same global state. If A finish all files while B just starts,
72+
// B would execute Reset function from InitLocal. If we don't set this 'if' branch, ring would be double freed.
73+
if(ring != nullptr) {
7474
// We don't use this function anymore since it slows down the speed
7575
// if(io_uring_unregister_buffers(ring) != 0) {
7676
// throw InvalidArgumentException("DirectUringRandomAccessFile::UnregisterBuffer: unregister buffer fails. ");
7777
// }
78-
io_uring_queue_exit(ring);
79-
free(iovecs);
80-
delete(ring);
81-
ring = nullptr;
82-
isRegistered = false;
83-
}
84-
78+
io_uring_queue_exit(ring);
79+
delete(ring);
80+
ring = nullptr;
81+
isRegistered = false;
82+
}
83+
if(iovecs != nullptr) {
84+
free(iovecs);
85+
iovecs = nullptr;
86+
}
8587
}
8688

8789
DirectUringRandomAccessFile::~DirectUringRandomAccessFile() {

0 commit comments

Comments
 (0)