Skip to content

Commit 795e8bb

Browse files
committed
Fix a premature object destruction bug. Thank you AddressSanitizer.
1 parent b8011ec commit 795e8bb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

ext/common/EventedBufferedInput.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ class EventedBufferedInput: public enable_shared_from_this< EventedBufferedInput
8484
}
8585

8686
void onReadable(ev::io &watcher, int revents) {
87+
// Keep 'this' alive until function exit.
88+
shared_ptr< EventedBufferedInput<bufferSize> > self = EventedBufferedInput<bufferSize>::shared_from_this();
89+
8790
ssize_t ret = syscalls::read(fd, bufferData, bufferSize);
8891
if (ret == -1) {
8992
if (errno != EAGAIN) {
@@ -97,8 +100,7 @@ class EventedBufferedInput: public enable_shared_from_this< EventedBufferedInput
97100
state = READ_ERROR;
98101
paused = true;
99102
if (onError != NULL) {
100-
onError(EventedBufferedInput<bufferSize>::shared_from_this(),
101-
"Cannot read from socket", error);
103+
onError(self, "Cannot read from socket", error);
102104
}
103105
}
104106

@@ -111,8 +113,7 @@ class EventedBufferedInput: public enable_shared_from_this< EventedBufferedInput
111113
watcher.stop();
112114
state = END_OF_STREAM;
113115
paused = true;
114-
onData(EventedBufferedInput<bufferSize>::shared_from_this(),
115-
StaticString());
116+
onData(self, StaticString());
116117

117118
} else {
118119
assert(state == LIVE);
@@ -153,7 +154,6 @@ class EventedBufferedInput: public enable_shared_from_this< EventedBufferedInput
153154
}
154155

155156
assert(buffer.size() > 0);
156-
157157
size_t consumed = onData(EventedBufferedInput<bufferSize>::shared_from_this(),
158158
buffer);
159159
if (state == CLOSED) {

ext/common/agents/Base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ dumpDiagnostics(AbortHandlerState &state) {
508508
write(STDERR_FILENO, messageBuf, end - messageBuf);
509509

510510
#ifdef LIBC_HAS_BACKTRACE_FUNC
511-
runInSubprocessWithTimeLimit(state, dumpBacktrace, NULL, 2000);
511+
runInSubprocessWithTimeLimit(state, dumpBacktrace, NULL, 4000);
512512
#endif
513513

514514
safePrintErr("--------------------------------------\n");

0 commit comments

Comments
 (0)