2010-06-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Fixed double memory free when Exception raised from
	AbstractCommand::prepareForNextAction() called by
	HttpResponseCommand::handleDefaultEncoding().
	* src/AbstractCommand.cc
	* src/HttpResponseCommand.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-06-01 12:40:57 +00:00
parent 9be631e007
commit 22ada0cf32
3 changed files with 39 additions and 32 deletions

View File

@ -1,3 +1,11 @@
2010-06-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed double memory free when Exception raised from
AbstractCommand::prepareForNextAction() called by
HttpResponseCommand::handleDefaultEncoding().
* src/AbstractCommand.cc
* src/HttpResponseCommand.cc
2010-06-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-06-01 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added _logger->info() guard Added _logger->info() guard

View File

@ -697,6 +697,9 @@ std::string AbstractCommand::resolveHostname
return ipaddr; return ipaddr;
} }
// nextCommand is going to be managed by CheckIntegrityEntry which is
// created in side this function. Don't release nextCommand after this
// function call.
void AbstractCommand::prepareForNextAction(Command* nextCommand) void AbstractCommand::prepareForNextAction(Command* nextCommand)
{ {
SharedHandle<CheckIntegrityEntry> entry SharedHandle<CheckIntegrityEntry> entry

View File

@ -233,39 +233,35 @@ bool HttpResponseCommand::handleDefaultEncoding
return true; return true;
} }
_requestGroup->loadAndOpenFile(infoFile);
File file(_requestGroup->getFirstFilePath());
// We have to make sure that command that has Request object must
// have segment after PieceStorage is initialized. See
// AbstractCommand::execute()
SharedHandle<Segment> segment =
_requestGroup->getSegmentMan()->getSegment(cuid, 0);
// pipelining requires implicit range specified. But the request for
// this response most likely dones't contains range header. This means
// we can't continue to use this socket because server sends all entity
// body instead of a segment.
// Therefore, we shutdown the socket here if pipelining is enabled.
DownloadCommand* command = 0; DownloadCommand* command = 0;
try { if(req->getMethod() == Request::METHOD_GET &&
_requestGroup->loadAndOpenFile(infoFile); !segment.isNull() && segment->getPositionToWrite() == 0 &&
File file(_requestGroup->getFirstFilePath()); !req->isPipeliningEnabled()) {
command = createHttpDownloadCommand
// We have to make sure that command that has Request object must (httpResponse, getTransferEncodingDecoder(httpResponse));
// have segment after PieceStorage is initialized. See } else {
// AbstractCommand::execute() _requestGroup->getSegmentMan()->cancelSegment(cuid);
SharedHandle<Segment> segment = _fileEntry->poolRequest(req);
_requestGroup->getSegmentMan()->getSegment(cuid, 0); }
// pipelining requires implicit range specified. But the request for // After command is passed to prepareForNextAction(), it is managed
// this response most likely dones't contains range header. This means // by CheckIntegrityEntry.
// we can't continue to use this socket because server sends all entity prepareForNextAction(command);
// body instead of a segment. command = 0;
// Therefore, we shutdown the socket here if pipelining is enabled. if(req->getMethod() == Request::METHOD_HEAD) {
if(req->getMethod() == Request::METHOD_GET && poolConnection();
!segment.isNull() && segment->getPositionToWrite() == 0 && req->setMethod(Request::METHOD_GET);
!req->isPipeliningEnabled()) {
command = createHttpDownloadCommand
(httpResponse, getTransferEncodingDecoder(httpResponse));
} else {
_requestGroup->getSegmentMan()->cancelSegment(cuid);
_fileEntry->poolRequest(req);
}
prepareForNextAction(command);
if(req->getMethod() == Request::METHOD_HEAD) {
poolConnection();
req->setMethod(Request::METHOD_GET);
}
} catch(Exception& e) {
delete command;
throw;
} }
return true; return true;
} }