summaryrefslogtreecommitdiff
path: root/src/MetaFileUtil.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-03-22 15:10:03 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-03-22 15:10:03 +0000
commit26aa28acb3793d3d992625fcaad5e45df336a9a3 (patch)
treed2e46f9ad50aa1a11ce8350494458cf8a9372caa /src/MetaFileUtil.cc
parentbf336caa83f28f02f0b60697af3d97c2e5156144 (diff)
* PeerInteractionCommand.cc: added a call to
TorrentMan::unadvertisePiece in Destructor. * PeerInteractionCommand.cc: make have message sent immediately if the size of pending message queue is zero. * TorrentMan.cc: set the maximum size of peer list to 250. * TorrentMan.h: changed the container type of Peers and UsedPieces to deque. * Util.cc: fixed rangedFileCopy. * AbstractDiskWriter.{h,cc}: moved digest context initialization to Constructor. Also, moved digest cleanup to Destructor. * MetaFileUtil.cc: fixed memory leak
Diffstat (limited to 'src/MetaFileUtil.cc')
-rw-r--r--src/MetaFileUtil.cc67
1 files changed, 43 insertions, 24 deletions
diff --git a/src/MetaFileUtil.cc b/src/MetaFileUtil.cc
index bfc662b6..b0c09bb7 100644
--- a/src/MetaFileUtil.cc
+++ b/src/MetaFileUtil.cc
@@ -31,17 +31,26 @@ MetaEntry* MetaFileUtil::parseMetaFile(string file) {
int len = f.size();
char* buf = new char[len];
FILE* fp = fopen(file.c_str(), "r+");
- if(fp == NULL) {
- throw new DlAbortEx("cannot open metainfo file");
- }
- if(fread(buf, len, 1, fp) != 1) {
+ try {
+ if(fp == NULL) {
+ throw new DlAbortEx("cannot open metainfo file");
+ }
+ if(fread(buf, len, 1, fp) != 1) {
+ fclose(fp);
+ throw new DlAbortEx("cannot read metainfo");
+ }
fclose(fp);
- throw new DlAbortEx("cannot read metainfo");
+ fp = NULL;
+ MetaEntry* entry = bdecoding(buf, len);
+ delete [] buf;
+ return entry;
+ } catch(Exception* ex) {
+ delete [] buf;
+ if(fp != NULL) {
+ fclose(fp);
+ }
+ throw;
}
- fclose(fp);
- MetaEntry* entry = bdecoding(buf, len);
- delete [] buf;
- return entry;
}
MetaEntry* MetaFileUtil::bdecoding(const char* buf, int len) {
@@ -88,16 +97,21 @@ Dictionary* MetaFileUtil::parseDictionaryTree(const char** pp, const char* end)
throw new DlAbortEx("mulformed metainfo");
}
Dictionary* dic = new Dictionary();
- while(1) {
- if(**pp == 'e') {
- (*pp)++;
- break;
+ try {
+ while(1) {
+ if(**pp == 'e') {
+ (*pp)++;
+ break;
+ }
+ string name = decodeWordAsString(pp, end);
+ MetaEntry* e = bdecodingR(pp, end);
+ dic->put(name, e);
}
- string name = decodeWordAsString(pp, end);
- MetaEntry* e = bdecodingR(pp, end);
- dic->put(name, e);
+ return dic;
+ } catch(Exception* ex) {
+ delete dic;
+ throw;
}
- return dic;
}
List* MetaFileUtil::parseListTree(const char** pp, const char* end) {
@@ -105,15 +119,20 @@ List* MetaFileUtil::parseListTree(const char** pp, const char* end) {
throw new DlAbortEx("mulformed metainfo");
}
List* lis = new List();
- while(1) {
- if(**pp == 'e') {
- (*pp)++;
- break;
+ try {
+ while(1) {
+ if(**pp == 'e') {
+ (*pp)++;
+ break;
+ }
+ MetaEntry* e = bdecodingR(pp, end);
+ lis->add(e);
}
- MetaEntry* e = bdecodingR(pp, end);
- lis->add(e);
+ return lis;
+ } catch(Exception* ex) {
+ delete lis;
+ throw;
}
- return lis;
}
Data* MetaFileUtil::decodeInt(const char** pp, const char* end) {