author | ulf69 <ulf69> | 2004-08-19 23:29:05 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-19 23:29:05 (UTC) |
commit | d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e (patch) (side-by-side diff) | |
tree | 9b723a5c4f7da306036495e35d1863fbee646984 /kabc | |
parent | d9b7a7296b031b3cf3e510a163367b9c4ab42d7a (diff) | |
download | kdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.zip kdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.tar.gz kdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.tar.bz2 |
bugfix: memoryleak in vCards during loading of addressbooks
-rw-r--r-- | kabc/vcard/ContentLine.cpp | 103 | ||||
-rw-r--r-- | kabc/vcard/VCardEntity.cpp | 23 | ||||
-rw-r--r-- | kabc/vcard/VCardv.cpp | 23 |
3 files changed, 97 insertions, 52 deletions
diff --git a/kabc/vcard/ContentLine.cpp b/kabc/vcard/ContentLine.cpp index 6fa1a8f..0fb5b5d 100644 --- a/kabc/vcard/ContentLine.cpp +++ b/kabc/vcard/ContentLine.cpp @@ -3,5 +3,5 @@ Copyright (C) 1999 Rik Hemsley rik@kde.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to @@ -69,4 +69,5 @@ ContentLine::ContentLine() value_(0) { + paramList_.setAutoDelete( TRUE ); } @@ -75,7 +76,22 @@ ContentLine::ContentLine(const ContentLine & x) group_ (x.group_), name_ (x.name_), - paramList_(x.paramList_), - value_(x.value_->clone()) +/*US paramList_(x.paramList_),*/ + value_(x.value_->clone()), + paramType_(x.paramType_), + valueType_(x.valueType_), + entityType_(x.entityType_) { + paramList_.setAutoDelete( TRUE ); + + + ParamListIterator it(x.paramList_); + for (; it.current(); ++it) + { + Param *p = new Param; + p->setName( it.current()->name() ); + p->setValue( it.current()->value() ); + paramList_.append(p); + } + } @@ -84,4 +100,5 @@ ContentLine::ContentLine(const QCString & s) value_(0) { + paramList_.setAutoDelete( TRUE ); } @@ -90,6 +107,14 @@ ContentLine::operator = (ContentLine & x) { if (*this == x) return *this; - - paramList_ = x.paramList(); + + ParamListIterator it(x.paramList_); + for (; it.current(); ++it) + { + Param *p = new Param; + p->setName( it.current()->name() ); + p->setValue( it.current()->value() ); + paramList_.append(p); + } + value_ = x.value_->clone(); @@ -111,7 +136,7 @@ ContentLine::operator == (ContentLine & x) { x.parse(); - + QPtrListIterator<Param> it(x.paramList()); - + if (!paramList_.find(it.current())) return false; @@ -130,40 +155,40 @@ ContentLine::_parse() { vDebug("parse"); - + // Unqote newlines strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); - + int split = strRep_.find(':'); - + if (split == -1) { // invalid content line vDebug("No ':'"); return; } - + QCString firstPart(strRep_.left(split)); QCString valuePart(strRep_.mid(split + 1)); - + split = firstPart.find('.'); - + if (split != -1) { group_ = firstPart.left(split); firstPart = firstPart.mid(split + 1); } - + vDebug("Group == " + group_); vDebug("firstPart == " + firstPart); vDebug("valuePart == " + valuePart); - + // Now we have the group, the name and param list together and the value. - + QStrList l; - + RTokenise(firstPart, ";", l); - + if (l.count() == 0) {// invalid - no name ! vDebug("No name for this content line !"); return; } - + name_ = l.at(0); @@ -171,14 +196,14 @@ ContentLine::_parse() // Remove the name part. l.remove(0u); - + entityType_ = EntityNameToEntityType(name_); paramType_ = EntityTypeToParamType(entityType_); - + unsigned int i = 0; - + // For each parameter, create a new parameter of the correct type. QStrListIterator it(l); - + for (; it.current(); ++it, i++) { @@ -190,19 +215,19 @@ ContentLine::_parse() continue; } - + QCString paraName = str.left(split); QCString paraValue = str.mid(split + 1); - + QStrList paraValues; RTokenise(paraValue, ",", paraValues); - + QStrListIterator it2( paraValues ); - - for(; it2.current(); ++it2) { - + + for(; it2.current(); ++it2) { + Param *p = new Param; p->setName( paraName ); p->setValue( *it2 ); - + paramList_.append(p); } @@ -212,9 +237,9 @@ ContentLine::_parse() valueType_ = EntityTypeToValueType(entityType_); - + // kdDebug(5710) << "valueType: " << valueType_ << endl; - + switch (valueType_) { - + case ValueSound: value_ = new SoundValue; break; case ValueAgent: value_ = new AgentValue; break; @@ -236,5 +261,5 @@ ContentLine::_parse() default: value_ = new TextValue; break; } - + *value_ = valuePart; } @@ -247,16 +272,16 @@ ContentLine::_assemble() QCString line; - + if (!group_.isEmpty()) line += group_ + '.'; - + line += name_; vDebug("Adding parameters"); ParamListIterator it(paramList_); - + for (; it.current(); ++it) line += ";" + it.current()->asString(); - + vDebug("Adding value"); if (value_ != 0) @@ -267,5 +292,5 @@ ContentLine::_assemble() // Quote newlines line = line.replace( QRegExp( "\n" ), "\\n" ); - + // Fold lines longer than 72 chars const int maxLen = 72; diff --git a/kabc/vcard/VCardEntity.cpp b/kabc/vcard/VCardEntity.cpp index 0c21e2f..0cd2086 100644 --- a/kabc/vcard/VCardEntity.cpp +++ b/kabc/vcard/VCardEntity.cpp @@ -3,5 +3,5 @@ Copyright (C) 1998 Rik Hemsley rik@kde.org - + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to @@ -32,4 +32,5 @@ VCardEntity::VCardEntity() : Entity() { + cardList_.setAutoDelete( TRUE ); } @@ -37,4 +38,5 @@ VCardEntity::VCardEntity(const VCardEntity & x) : Entity(x) { + cardList_.setAutoDelete( TRUE ); } @@ -42,4 +44,5 @@ VCardEntity::VCardEntity(const QCString & s) : Entity(s) { + cardList_.setAutoDelete( TRUE ); } @@ -76,19 +79,19 @@ VCardEntity::_parse() vDebug("parse"); QCString s(strRep_); - + int i = s.find(QRegExp("BEGIN:VCARD", false)); - + while (i != -1) { - + i = s.find(QRegExp("BEGIN:VCARD", false), 11); - + QCString cardStr(s.left(i)); - + VCard * v = new VCard(cardStr); - + cardList_.append(v); - + v->parse(); - + s.remove(0, i); } @@ -99,5 +102,5 @@ VCardEntity::_assemble() { VCardListIterator it(cardList_); - + for (; it.current(); ++it) strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. diff --git a/kabc/vcard/VCardv.cpp b/kabc/vcard/VCardv.cpp index 8d271f4..3f0a5e5 100644 --- a/kabc/vcard/VCardv.cpp +++ b/kabc/vcard/VCardv.cpp @@ -37,11 +37,21 @@ VCard::VCard() : Entity() { + contentLineList_.setAutoDelete( TRUE ); } VCard::VCard(const VCard & x) : Entity(x), - group_(x.group_), - contentLineList_(x.contentLineList_) + group_(x.group_) { + contentLineList_.setAutoDelete( TRUE ); + //US + qDebug("VCard::VCard"); + + QPtrListIterator<ContentLine> it(x.contentLineList_); + for (; it.current(); ++it) { + ContentLine * c = new ContentLine(*it.current()); + contentLineList_.append(c); + } + } @@ -49,4 +59,5 @@ VCard::VCard(const QCString & s) : Entity(s) { + contentLineList_.setAutoDelete( TRUE ); } @@ -54,8 +65,14 @@ VCard::VCard(const QCString & s) VCard::operator = (VCard & x) { + //US + qDebug("VCard::operator ="); if (*this == x) return *this; group_ = x.group(); - contentLineList_ = x.contentLineList_; + QPtrListIterator<ContentLine> it(x.contentLineList_); + for (; it.current(); ++it) { + ContentLine * c = new ContentLine(*it.current()); + contentLineList_.append(c); + } Entity::operator = (x); |