Skip to content

Commit

Permalink
Fix fdstreambuf crash on bsd.
Browse files Browse the repository at this point in the history
libc++ would clear unique_ptr value before destructor, this makes the
private class destructor can not access q_ptr member that access d_ptr
(which is null at that point).
  • Loading branch information
wengxt committed Feb 7, 2025
1 parent 8563c43 commit 9c093a1
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/lib/fcitx-utils/fdstreambuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,6 @@ class OFDStreamBufPrivate : public QPtrHolder<OFDStreamBuf> {
resetBuffer();
}

~OFDStreamBufPrivate() {
FCITX_Q();
if (q->is_open()) {
q->sync();
}
}

void resetBuffer() {
FCITX_Q();
q->setp(buffer_.get(), buffer_.get() + OBufferSize - 1);
Expand All @@ -259,7 +252,11 @@ OFDStreamBuf::OFDStreamBuf(int fd)
d->fd_ = fd;
}

OFDStreamBuf::~OFDStreamBuf() {}
OFDStreamBuf::~OFDStreamBuf() {
if (is_open()) {
sync();
}
}

bool OFDStreamBuf::is_open() const noexcept {
FCITX_D();
Expand Down

0 comments on commit 9c093a1

Please sign in to comment.