summaryrefslogtreecommitdiffabout
authorulf69 <ulf69>2004-08-19 23:29:05 (UTC)
committer ulf69 <ulf69>2004-08-19 23:29:05 (UTC)
commitd81fbb0a720ba6eb0fbfa1d1eb0748877237a27e (patch) (unidiff)
tree9b723a5c4f7da306036495e35d1863fbee646984
parentd9b7a7296b031b3cf3e510a163367b9c4ab42d7a (diff)
downloadkdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.zip
kdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.tar.gz
kdepimpi-d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e.tar.bz2
bugfix: memoryleak in vCards during loading of addressbooks
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/vcard/ContentLine.cpp103
-rw-r--r--kabc/vcard/VCardEntity.cpp23
-rw-r--r--kabc/vcard/VCardv.cpp23
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 @@
3 3
4 Copyright (C) 1999 Rik Hemsley rik@kde.org 4 Copyright (C) 1999 Rik Hemsley rik@kde.org
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy 6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to 7 of this software and associated documentation files (the "Software"), to
@@ -69,4 +69,5 @@ ContentLine::ContentLine()
69 value_(0) 69 value_(0)
70{ 70{
71 paramList_.setAutoDelete( TRUE );
71} 72}
72 73
@@ -75,7 +76,22 @@ ContentLine::ContentLine(const ContentLine & x)
75 group_ (x.group_), 76 group_ (x.group_),
76 name_ (x.name_), 77 name_ (x.name_),
77 paramList_(x.paramList_), 78 /*US paramList_(x.paramList_),*/
78 value_(x.value_->clone()) 79 value_(x.value_->clone()),
80 paramType_(x.paramType_),
81 valueType_(x.valueType_),
82 entityType_(x.entityType_)
79{ 83{
84 paramList_.setAutoDelete( TRUE );
85
86
87 ParamListIterator it(x.paramList_);
88 for (; it.current(); ++it)
89 {
90 Param *p = new Param;
91 p->setName( it.current()->name() );
92 p->setValue( it.current()->value() );
93 paramList_.append(p);
94 }
95
80} 96}
81 97
@@ -84,4 +100,5 @@ ContentLine::ContentLine(const QCString & s)
84 value_(0) 100 value_(0)
85{ 101{
102 paramList_.setAutoDelete( TRUE );
86} 103}
87 104
@@ -90,6 +107,14 @@ ContentLine::operator = (ContentLine & x)
90{ 107{
91 if (*this == x) return *this; 108 if (*this == x) return *this;
92 109
93 paramList_ = x.paramList(); 110 ParamListIterator it(x.paramList_);
111 for (; it.current(); ++it)
112 {
113 Param *p = new Param;
114 p->setName( it.current()->name() );
115 p->setValue( it.current()->value() );
116 paramList_.append(p);
117 }
118
94 value_ = x.value_->clone(); 119 value_ = x.value_->clone();
95 120
@@ -111,7 +136,7 @@ ContentLine::operator == (ContentLine & x)
111{ 136{
112 x.parse(); 137 x.parse();
113 138
114 QPtrListIterator<Param> it(x.paramList()); 139 QPtrListIterator<Param> it(x.paramList());
115 140
116 if (!paramList_.find(it.current())) 141 if (!paramList_.find(it.current()))
117 return false; 142 return false;
@@ -130,40 +155,40 @@ ContentLine::_parse()
130{ 155{
131 vDebug("parse"); 156 vDebug("parse");
132 157
133 // Unqote newlines 158 // Unqote newlines
134 strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" ); 159 strRep_ = strRep_.replace( QRegExp( "\\\\n" ), "\n" );
135 160
136 int split = strRep_.find(':'); 161 int split = strRep_.find(':');
137 162
138 if (split == -1) { // invalid content line 163 if (split == -1) { // invalid content line
139 vDebug("No ':'"); 164 vDebug("No ':'");
140 return; 165 return;
141 } 166 }
142 167
143 QCString firstPart(strRep_.left(split)); 168 QCString firstPart(strRep_.left(split));
144 QCString valuePart(strRep_.mid(split + 1)); 169 QCString valuePart(strRep_.mid(split + 1));
145 170
146 split = firstPart.find('.'); 171 split = firstPart.find('.');
147 172
148 if (split != -1) { 173 if (split != -1) {
149 group_ = firstPart.left(split); 174 group_ = firstPart.left(split);
150 firstPart= firstPart.mid(split + 1); 175 firstPart= firstPart.mid(split + 1);
151 } 176 }
152 177
153 vDebug("Group == " + group_); 178 vDebug("Group == " + group_);
154 vDebug("firstPart == " + firstPart); 179 vDebug("firstPart == " + firstPart);
155 vDebug("valuePart == " + valuePart); 180 vDebug("valuePart == " + valuePart);
156 181
157 // Now we have the group, the name and param list together and the value. 182 // Now we have the group, the name and param list together and the value.
158 183
159 QStrList l; 184 QStrList l;
160 185
161 RTokenise(firstPart, ";", l); 186 RTokenise(firstPart, ";", l);
162 187
163 if (l.count() == 0) {// invalid - no name ! 188 if (l.count() == 0) {// invalid - no name !
164 vDebug("No name for this content line !"); 189 vDebug("No name for this content line !");
165 return; 190 return;
166 } 191 }
167 192
168 name_ = l.at(0); 193 name_ = l.at(0);
169 194
@@ -171,14 +196,14 @@ ContentLine::_parse()
171 // Remove the name part. 196 // Remove the name part.
172 l.remove(0u); 197 l.remove(0u);
173 198
174 entityType_= EntityNameToEntityType(name_); 199 entityType_= EntityNameToEntityType(name_);
175 paramType_= EntityTypeToParamType(entityType_); 200 paramType_= EntityTypeToParamType(entityType_);
176 201
177 unsigned int i = 0; 202 unsigned int i = 0;
178 203
179 // For each parameter, create a new parameter of the correct type. 204 // For each parameter, create a new parameter of the correct type.
180 205
181 QStrListIterator it(l); 206 QStrListIterator it(l);
182 207
183 for (; it.current(); ++it, i++) { 208 for (; it.current(); ++it, i++) {
184 209
@@ -190,19 +215,19 @@ ContentLine::_parse()
190 continue; 215 continue;
191 } 216 }
192 217
193 QCString paraName = str.left(split); 218 QCString paraName = str.left(split);
194 QCString paraValue = str.mid(split + 1); 219 QCString paraValue = str.mid(split + 1);
195 220
196 QStrList paraValues; 221 QStrList paraValues;
197 RTokenise(paraValue, ",", paraValues); 222 RTokenise(paraValue, ",", paraValues);
198 223
199 QStrListIterator it2( paraValues ); 224 QStrListIterator it2( paraValues );
200 225
201 for(; it2.current(); ++it2) { 226 for(; it2.current(); ++it2) {
202 227
203 Param *p = new Param; 228 Param *p = new Param;
204 p->setName( paraName ); 229 p->setName( paraName );
205 p->setValue( *it2 ); 230 p->setValue( *it2 );
206 231
207 paramList_.append(p); 232 paramList_.append(p);
208 } 233 }
@@ -212,9 +237,9 @@ ContentLine::_parse()
212 237
213 valueType_ = EntityTypeToValueType(entityType_); 238 valueType_ = EntityTypeToValueType(entityType_);
214 239
215 //kdDebug(5710) << "valueType: " << valueType_ << endl; 240 //kdDebug(5710) << "valueType: " << valueType_ << endl;
216 241
217 switch (valueType_) { 242 switch (valueType_) {
218 243
219 case ValueSound: value_ = new SoundValue;break; 244 case ValueSound: value_ = new SoundValue;break;
220 case ValueAgent: value_ = new AgentValue;break; 245 case ValueAgent: value_ = new AgentValue;break;
@@ -236,5 +261,5 @@ ContentLine::_parse()
236 default: value_ = new TextValue; break; 261 default: value_ = new TextValue; break;
237 } 262 }
238 263
239 *value_ = valuePart; 264 *value_ = valuePart;
240} 265}
@@ -247,16 +272,16 @@ ContentLine::_assemble()
247 272
248 QCString line; 273 QCString line;
249 274
250 if (!group_.isEmpty()) 275 if (!group_.isEmpty())
251 line += group_ + '.'; 276 line += group_ + '.';
252 277
253 line += name_; 278 line += name_;
254 279
255 vDebug("Adding parameters"); 280 vDebug("Adding parameters");
256 ParamListIterator it(paramList_); 281 ParamListIterator it(paramList_);
257 282
258 for (; it.current(); ++it) 283 for (; it.current(); ++it)
259 line += ";" + it.current()->asString(); 284 line += ";" + it.current()->asString();
260 285
261 vDebug("Adding value"); 286 vDebug("Adding value");
262 if (value_ != 0) 287 if (value_ != 0)
@@ -267,5 +292,5 @@ ContentLine::_assemble()
267 // Quote newlines 292 // Quote newlines
268 line = line.replace( QRegExp( "\n" ), "\\n" ); 293 line = line.replace( QRegExp( "\n" ), "\\n" );
269 294
270 // Fold lines longer than 72 chars 295 // Fold lines longer than 72 chars
271 const int maxLen = 72; 296 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 @@
3 3
4 Copyright (C) 1998 Rik Hemsley rik@kde.org 4 Copyright (C) 1998 Rik Hemsley rik@kde.org
5 5
6 Permission is hereby granted, free of charge, to any person obtaining a copy 6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to 7 of this software and associated documentation files (the "Software"), to
@@ -32,4 +32,5 @@ VCardEntity::VCardEntity()
32 :Entity() 32 :Entity()
33{ 33{
34 cardList_.setAutoDelete( TRUE );
34} 35}
35 36
@@ -37,4 +38,5 @@ VCardEntity::VCardEntity(const VCardEntity & x)
37 :Entity(x) 38 :Entity(x)
38{ 39{
40 cardList_.setAutoDelete( TRUE );
39} 41}
40 42
@@ -42,4 +44,5 @@ VCardEntity::VCardEntity(const QCString & s)
42 :Entity(s) 44 :Entity(s)
43{ 45{
46 cardList_.setAutoDelete( TRUE );
44} 47}
45 48
@@ -76,19 +79,19 @@ VCardEntity::_parse()
76 vDebug("parse"); 79 vDebug("parse");
77 QCString s(strRep_); 80 QCString s(strRep_);
78 81
79 int i = s.find(QRegExp("BEGIN:VCARD", false)); 82 int i = s.find(QRegExp("BEGIN:VCARD", false));
80 83
81 while (i != -1) { 84 while (i != -1) {
82 85
83 i = s.find(QRegExp("BEGIN:VCARD", false), 11); 86 i = s.find(QRegExp("BEGIN:VCARD", false), 11);
84 87
85 QCString cardStr(s.left(i)); 88 QCString cardStr(s.left(i));
86 89
87 VCard * v = new VCard(cardStr); 90 VCard * v = new VCard(cardStr);
88 91
89 cardList_.append(v); 92 cardList_.append(v);
90 93
91 v->parse(); 94 v->parse();
92 95
93 s.remove(0, i); 96 s.remove(0, i);
94 } 97 }
@@ -99,5 +102,5 @@ VCardEntity::_assemble()
99{ 102{
100 VCardListIterator it(cardList_); 103 VCardListIterator it(cardList_);
101 104
102 for (; it.current(); ++it) 105 for (; it.current(); ++it)
103 strRep_ += it.current()->asString() + "\r\n"; // One CRLF for luck. 106 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()
37 :Entity() 37 :Entity()
38{ 38{
39 contentLineList_.setAutoDelete( TRUE );
39} 40}
40 41
41VCard::VCard(const VCard & x) 42VCard::VCard(const VCard & x)
42 :Entity(x), 43 :Entity(x),
43 group_(x.group_), 44 group_(x.group_)
44 contentLineList_(x.contentLineList_)
45{ 45{
46 contentLineList_.setAutoDelete( TRUE );
47 //US
48 qDebug("VCard::VCard");
49
50 QPtrListIterator<ContentLine> it(x.contentLineList_);
51 for (; it.current(); ++it) {
52 ContentLine * c = new ContentLine(*it.current());
53 contentLineList_.append(c);
54 }
55
46} 56}
47 57
@@ -49,4 +59,5 @@ VCard::VCard(const QCString & s)
49 :Entity(s) 59 :Entity(s)
50{ 60{
61 contentLineList_.setAutoDelete( TRUE );
51} 62}
52 63
@@ -54,8 +65,14 @@ VCard::VCard(const QCString & s)
54VCard::operator = (VCard & x) 65VCard::operator = (VCard & x)
55{ 66{
67 //US
68 qDebug("VCard::operator =");
56 if (*this == x) return *this; 69 if (*this == x) return *this;
57 70
58 group_ = x.group(); 71 group_ = x.group();
59 contentLineList_= x.contentLineList_; 72 QPtrListIterator<ContentLine> it(x.contentLineList_);
73 for (; it.current(); ++it) {
74 ContentLine * c = new ContentLine(*it.current());
75 contentLineList_.append(c);
76 }
60 77
61 Entity::operator = (x); 78 Entity::operator = (x);