From d81fbb0a720ba6eb0fbfa1d1eb0748877237a27e Mon Sep 17 00:00:00 2001 From: ulf69 Date: Thu, 19 Aug 2004 23:29:05 +0000 Subject: bugfix: memoryleak in vCards during loading of addressbooks --- (limited to 'kabc/vcard/ContentLine.cpp') 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 @@ -2,7 +2,7 @@ libvcard - vCard parsing library for vCard version 3.0 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 deal in the Software without restriction, including without limitation the @@ -68,29 +68,54 @@ ContentLine::ContentLine() : Entity(), value_(0) { + paramList_.setAutoDelete( TRUE ); } ContentLine::ContentLine(const ContentLine & x) : Entity(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); + } + } ContentLine::ContentLine(const QCString & s) : Entity(s), value_(0) { + paramList_.setAutoDelete( TRUE ); } ContentLine & 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(); Entity::operator = (x); @@ -110,9 +135,9 @@ ContentLine::operator = (const QCString & s) ContentLine::operator == (ContentLine & x) { x.parse(); - + QPtrListIterator it(x.paramList()); - + if (!paramList_.find(it.current())) return false; @@ -129,57 +154,57 @@ ContentLine::~ContentLine() 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); // Now we have the name, so the rest of 'l' is the params. // 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++) { QCString str = *it; @@ -189,21 +214,21 @@ ContentLine::_parse() vDebug("No '=' in paramter."); 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); } } @@ -211,11 +236,11 @@ ContentLine::_parse() // Create a new value of the correct type. valueType_ = EntityTypeToValueType(entityType_); - + // kdDebug(5710) << "valueType: " << valueType_ << endl; - + switch (valueType_) { - + case ValueSound: value_ = new SoundValue; break; case ValueAgent: value_ = new AgentValue; break; case ValueAddress: value_ = new AdrValue; break; @@ -235,7 +260,7 @@ ContentLine::_parse() case ValueUnknown: default: value_ = new TextValue; break; } - + *value_ = valuePart; } @@ -246,18 +271,18 @@ ContentLine::_assemble() strRep_.truncate(0); 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) line += ":" + value_->asString(); @@ -266,7 +291,7 @@ ContentLine::_assemble() // Quote newlines line = line.replace( QRegExp( "\n" ), "\\n" ); - + // Fold lines longer than 72 chars const int maxLen = 72; uint cursor = 0; -- cgit v0.9.0.2