Skip to content

Commit

Permalink
2010-11-11 Tatsuhiro Tsujikawa <[email protected]>
Browse files Browse the repository at this point in the history
	Create SharedHandle outside of function call to avoid unexpected
	memory leak.
	* src/AnnounceList.cc
	* src/FtpNegotiationCommand.cc
	* src/HttpResponseCommand.cc
	* src/RequestGroup.cc
	* src/RequestGroupMan.cc
	* src/UTMetadataPostDownloadHandler.cc
	* src/download_helper.cc
  • Loading branch information
tatsuhiro-t committed Nov 11, 2010
1 parent e728385 commit bcf4593
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 31 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2010-11-11 Tatsuhiro Tsujikawa <[email protected]>

Create SharedHandle outside of function call to avoid unexpected
memory leak.
* src/AnnounceList.cc
* src/FtpNegotiationCommand.cc
* src/HttpResponseCommand.cc
* src/RequestGroup.cc
* src/RequestGroupMan.cc
* src/UTMetadataPostDownloadHandler.cc
* src/download_helper.cc

2010-11-11 Tatsuhiro Tsujikawa <[email protected]>

Updated supported hash functions.
Expand Down
3 changes: 2 additions & 1 deletion src/AnnounceList.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void AnnounceList::reconfigure
void AnnounceList::reconfigure(const std::string& url) {
std::deque<std::string> urls;
urls.push_back(url);
tiers_.push_back(SharedHandle<AnnounceTier>(new AnnounceTier(urls)));
SharedHandle<AnnounceTier> tier(new AnnounceTier(urls));
tiers_.push_back(tier);
resetIterator();
}

Expand Down
10 changes: 4 additions & 6 deletions src/FtpNegotiationCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,10 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
getSegmentMan()->getSegmentWithIndex(getCuid(), 0);
return true;
} else {
getRequestGroup()->adjustFilename
(SharedHandle<BtProgressInfoFile>
(new DefaultBtProgressInfoFile
(getDownloadContext(),
SharedHandle<PieceStorage>(),
getOption().get())));
SharedHandle<BtProgressInfoFile> progressInfoFile
(new DefaultBtProgressInfoFile
(getDownloadContext(), SharedHandle<PieceStorage>(), getOption().get()));
getRequestGroup()->adjustFilename(progressInfoFile);
getRequestGroup()->initPieceStorage();

if(getOption()->getAsBool(PREF_DRY_RUN)) {
Expand Down
9 changes: 4 additions & 5 deletions src/HttpResponseCommand.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,10 @@ bool HttpResponseCommand::handleDefaultEncoding
(const SharedHandle<HttpResponse>& httpResponse)
{
SharedHandle<HttpRequest> httpRequest = httpResponse->getHttpRequest();
getRequestGroup()->adjustFilename
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
(getDownloadContext(),
SharedHandle<PieceStorage>(),
getOption().get())));
SharedHandle<BtProgressInfoFile> progressInfoFile
(new DefaultBtProgressInfoFile
(getDownloadContext(), SharedHandle<PieceStorage>(), getOption().get()));
getRequestGroup()->adjustFilename(progressInfoFile);
getRequestGroup()->initPieceStorage();

if(getOption()->getAsBool(PREF_DRY_RUN)) {
Expand Down
14 changes: 7 additions & 7 deletions src/RequestGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,10 @@ void RequestGroup::createInitialCommand
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
downloadContext_->getBasePath().c_str()).str());
}
adjustFilename
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
(downloadContext_,
SharedHandle<PieceStorage>(),
option_.get())));
SharedHandle<BtProgressInfoFile> progressInfoFile
(new DefaultBtProgressInfoFile
(downloadContext_, SharedHandle<PieceStorage>(), option_.get()));
adjustFilename(progressInfoFile);
initPieceStorage();
SharedHandle<CheckIntegrityEntry> checkEntry =
createCheckIntegrityEntry();
Expand Down Expand Up @@ -601,8 +600,9 @@ void RequestGroup::initPieceStorage()
if(logger_->debug()) {
logger_->debug("Using LongestSequencePieceSelector");
}
ps->setPieceSelector
(SharedHandle<PieceSelector>(new LongestSequencePieceSelector()));
SharedHandle<PieceSelector> longestPieceSelector
(new LongestSequencePieceSelector());
ps->setPieceSelector(longestPieceSelector);
}
if(option_->defined(PREF_BT_PRIORITIZE_PIECE)) {
std::vector<size_t> result;
Expand Down
16 changes: 8 additions & 8 deletions src/RequestGroupMan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,22 +463,22 @@ void RequestGroupMan::configureRequestGroup
{
const std::string& uriSelectorValue = option_->get(PREF_URI_SELECTOR);
if(uriSelectorValue == V_FEEDBACK) {
requestGroup->setURISelector
(SharedHandle<URISelector>(new FeedbackURISelector(serverStatMan_)));
SharedHandle<URISelector> sel(new FeedbackURISelector(serverStatMan_));
requestGroup->setURISelector(sel);
} else if(uriSelectorValue == V_INORDER) {
requestGroup->setURISelector
(SharedHandle<URISelector>(new InOrderURISelector()));
SharedHandle<URISelector> sel(new InOrderURISelector());
requestGroup->setURISelector(sel);
} else if(uriSelectorValue == V_ADAPTIVE) {
requestGroup->setURISelector
(SharedHandle<URISelector>(new AdaptiveURISelector(serverStatMan_,
requestGroup.get())));
SharedHandle<URISelector> sel(new AdaptiveURISelector(serverStatMan_,
requestGroup.get()));
requestGroup->setURISelector(sel);
}
}

namespace {
void createInitialCommand(const SharedHandle<RequestGroup>& requestGroup,
std::vector<Command*>& commands,
DownloadEngine* e)
DownloadEngine* e)
{
requestGroup->createInitialCommand(commands, e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/UTMetadataPostDownloadHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ bool UTMetadataPostDownloadHandler::Criteria::match
UTMetadataPostDownloadHandler::UTMetadataPostDownloadHandler():
logger_(LogFactory::getInstance())
{
setCriteria(SharedHandle<Criteria>(new Criteria()));
SharedHandle<Criteria> cri(new Criteria());
setCriteria(cri);
}

void UTMetadataPostDownloadHandler::getNextRequestGroups
Expand Down
6 changes: 3 additions & 3 deletions src/download_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ createBtMagnetRequestGroup(const std::string& magnetLink,
dctx->getFirstFileEntry()->setPath(torrentAttrs->name);
rg->setDownloadContext(dctx);
rg->clearPostDownloadHandler();
rg->addPostDownloadHandler
(SharedHandle<UTMetadataPostDownloadHandler>
(new UTMetadataPostDownloadHandler()));
SharedHandle<UTMetadataPostDownloadHandler> utMetadataPostHandler
(new UTMetadataPostDownloadHandler());
rg->addPostDownloadHandler(utMetadataPostHandler);
rg->setDiskWriterFactory
(SharedHandle<DiskWriterFactory>(new ByteArrayDiskWriterFactory()));
rg->setMetadataInfo(createMetadataInfo(magnetLink));
Expand Down

0 comments on commit bcf4593

Please sign in to comment.