Skip to content

Commit

Permalink
Fix a premature object destruction bug. Thank you AddressSanitizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
FooBarWidget committed Jul 12, 2012
1 parent b8011ec commit 795e8bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions ext/common/EventedBufferedInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class EventedBufferedInput: public enable_shared_from_this< EventedBufferedInput
}

void onReadable(ev::io &watcher, int revents) {
// Keep 'this' alive until function exit.
shared_ptr< EventedBufferedInput<bufferSize> > self = EventedBufferedInput<bufferSize>::shared_from_this();

ssize_t ret = syscalls::read(fd, bufferData, bufferSize);
if (ret == -1) {
if (errno != EAGAIN) {
Expand All @@ -97,8 +100,7 @@ class EventedBufferedInput: public enable_shared_from_this< EventedBufferedInput
state = READ_ERROR;
paused = true;
if (onError != NULL) {
onError(EventedBufferedInput<bufferSize>::shared_from_this(),
"Cannot read from socket", error);
onError(self, "Cannot read from socket", error);
}
}

Expand All @@ -111,8 +113,7 @@ class EventedBufferedInput: public enable_shared_from_this< EventedBufferedInput
watcher.stop();
state = END_OF_STREAM;
paused = true;
onData(EventedBufferedInput<bufferSize>::shared_from_this(),
StaticString());
onData(self, StaticString());

} else {
assert(state == LIVE);
Expand Down Expand Up @@ -153,7 +154,6 @@ class EventedBufferedInput: public enable_shared_from_this< EventedBufferedInput
}

assert(buffer.size() > 0);

size_t consumed = onData(EventedBufferedInput<bufferSize>::shared_from_this(),
buffer);
if (state == CLOSED) {
Expand Down
2 changes: 1 addition & 1 deletion ext/common/agents/Base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ dumpDiagnostics(AbortHandlerState &state) {
write(STDERR_FILENO, messageBuf, end - messageBuf);

#ifdef LIBC_HAS_BACKTRACE_FUNC
runInSubprocessWithTimeLimit(state, dumpBacktrace, NULL, 2000);
runInSubprocessWithTimeLimit(state, dumpBacktrace, NULL, 4000);
#endif

safePrintErr("--------------------------------------\n");
Expand Down

0 comments on commit 795e8bb

Please sign in to comment.