From: Alex Rousskov Date: Tue, 10 Apr 2012 12:14:30 +0000 (-0600) Subject: Bug 3505: crash in CbcPointer constructor X-Git-Tag: SQUID_3_2_0_17~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3d37e753d68e77867244dd93cb17b4545a715a5;p=thirdparty%2Fsquid.git Bug 3505: crash in CbcPointer constructor --- diff --git a/src/comm/ConnOpener.cc b/src/comm/ConnOpener.cc index 7883cea327..0ed365198a 100644 --- a/src/comm/ConnOpener.cc +++ b/src/comm/ConnOpener.cc @@ -241,7 +241,7 @@ Comm::ConnOpener::connect() return; } else { debugs(5, 5, HERE << conn_ << ": COMM_INPROGRESS"); - Comm::SetSelect(temporaryFd_, COMM_SELECT_WRITE, Comm::ConnOpener::InProgressConnectRetry, this, 0); + Comm::SetSelect(temporaryFd_, COMM_SELECT_WRITE, Comm::ConnOpener::InProgressConnectRetry, new Pointer(this), 0); } break; @@ -261,7 +261,7 @@ Comm::ConnOpener::connect() doneConnecting(COMM_TIMEOUT, errno); } else if (failRetries_ < Config.connect_retries) { debugs(5, 5, HERE << conn_ << ": * - try again"); - eventAdd("Comm::ConnOpener::DelayedConnectRetry", Comm::ConnOpener::DelayedConnectRetry, this, 0.05, 0); + eventAdd("Comm::ConnOpener::DelayedConnectRetry", Comm::ConnOpener::DelayedConnectRetry, new Pointer(this), 0.05, 0); return; } else { // send ERROR back to the upper layer. @@ -319,14 +319,16 @@ Comm::ConnOpener::timeout(const CommTimeoutCbParams &) void Comm::ConnOpener::InProgressConnectRetry(int fd, void *data) { - ConnOpener *cs = static_cast(data); - assert(cs); - - // Ew. we are now outside the all AsyncJob protections. - // get back inside by scheduling another call... - typedef NullaryMemFunT Dialer; - AsyncCall::Pointer call = JobCallback(5, 4, Dialer, cs, Comm::ConnOpener::connect); - ScheduleCallHere(call); + Pointer *ptr = static_cast(data); + assert(ptr); + if (ConnOpener *cs = ptr->valid()) { + // Ew. we are now outside the all AsyncJob protections. + // get back inside by scheduling another call... + typedef NullaryMemFunT Dialer; + AsyncCall::Pointer call = JobCallback(5, 4, Dialer, cs, Comm::ConnOpener::connect); + ScheduleCallHere(call); + } + delete ptr; } /* Legacy Wrapper for the retry event with small delay after errors. @@ -335,12 +337,14 @@ Comm::ConnOpener::InProgressConnectRetry(int fd, void *data) void Comm::ConnOpener::DelayedConnectRetry(void *data) { - ConnOpener *cs = static_cast(data); - assert(cs); - - // Ew. we are now outside the all AsyncJob protections. - // get back inside by scheduling another call... - typedef NullaryMemFunT Dialer; - AsyncCall::Pointer call = JobCallback(5, 4, Dialer, cs, Comm::ConnOpener::connect); - ScheduleCallHere(call); + Pointer *ptr = static_cast(data); + assert(ptr); + if (ConnOpener *cs = ptr->valid()) { + // Ew. we are now outside the all AsyncJob protections. + // get back inside by scheduling another call... + typedef NullaryMemFunT Dialer; + AsyncCall::Pointer call = JobCallback(5, 4, Dialer, cs, Comm::ConnOpener::connect); + ScheduleCallHere(call); + } + delete ptr; } diff --git a/src/comm/ConnOpener.h b/src/comm/ConnOpener.h index 05fcd550f5..25c2b9a2b6 100644 --- a/src/comm/ConnOpener.h +++ b/src/comm/ConnOpener.h @@ -21,6 +21,8 @@ protected: virtual void swanSong(); public: + typedef CbcPointer Pointer; + virtual bool doneAll() const; ConnOpener(Comm::ConnectionPointer &, AsyncCall::Pointer &handler, time_t connect_timeout);