USER 44

Login to reply to this topic.
Sat, 2008-03-08 10:48
Joined: 2006-12-19
Forum posts: 72

Hi everybody,

i have a problem with the following code.
When i create an object of CXMLElement class dynamically and call its functions
as shown in the following function.

void CXmlHandler::OnStartElementL( const RTagInfo& aElement,
        const RAttributeArray& aAttributes, TInt aErrorCode )
    {
    if ( KErrNone == aErrorCode )
        {
        // If we find the start of an element, we write to the screen,
        // for example: "<tag>"
        //AppendTag( aElement.LocalName().DesC(), EFalse );
                        iXmlElement = CXMLElement::NewL();
                        iXmlElement->SetElementNameL(aElement.LocalName().DesC());
                        TInt count = aAttributes.Count();
                       
                        for(TInt i=0; i<count; i++)
                        {
                                const TDesC8& name = aAttributes[i].Attribute().LocalName().DesC();
                                const TDesC8& value = aAttributes[i].Value().DesC();
                                iXmlElement->AddAttributeL(name,value);
                        }
                       
                        delete iXmlElement;
        }
    else
        {
        iObserver.OnParseCompleted( aErrorCode );
        }
    }

It gives USER 44 error.

please help me in solvin this problem.
I think i have memory problem in my code.If it is any please me suggest to remove it.
The implementation code of the CXMLElement class is given below.

#include "XMLData.h"
CXMLElement::CXMLElement()
{
        ElementName=NULL;
        AttributeCount=0;
        for(int i=0;i<MAX_ATTRIBUTE;i++)
        {
                attribute[i].AttributeName = NULL;
                attribute[i].AttributeValue = NULL;
        }
}
void CXMLElement::ConstructL()
{       
}
CXMLElement* CXMLElement::NewL()
{
        CXMLElement* self = CXMLElement::NewLC();
        CleanupStack::Pop();
        return self;
}
CXMLElement* CXMLElement::NewLC()
{
        CXMLElement* self = new ( ELeave ) CXMLElement();
        CleanupStack::PushL( self );
        self->ConstructL();
        return self;
}

CXMLElement::~CXMLElement()
{
        delete ElementName;
        for(int i=0;i<AttributeCount;i++)
        {
                delete attribute[i].AttributeName;
                delete attribute[i].AttributeValue;
        }
}
void CXMLElement::SetElementNameL(const TDesC8& EName)
{
        ElementName = HBufC8::NewLC(EName.Length());
        TPtr8 ptr8(ElementName->Des());
        ptr8.Copy(EName);
}
TPtr8 CXMLElement::GetElementName()
{
        return ElementName->Des();
}
void CXMLElement::AddAttributeL(const TDesC8& AName ,const TDesC8& AValue)
{
        if(AttributeCount<=MAX_ATTRIBUTE)
        {
                attribute[AttributeCount].AttributeName = HBufC8::NewLC(AName.Length());
                TPtr8 ptrName(attribute[AttributeCount].AttributeName->Des());
                ptrName.Copy(AName);

                attribute[AttributeCount].AttributeValue = HBufC8::NewLC(AValue.Length());
                TPtr8 ptrValue(attribute[AttributeCount].AttributeValue->Des());
                ptrValue.Copy(AValue);

                AttributeCount++;//Incrementing the Attribute Count
        }
}
TPtr8 CXMLElement::GetAttributeName(int index)
{
        if(index<=AttributeCount&&index>=0)
        {
                return attribute


.AttributeName->Des();
        }
}
TPtr8 CXMLElement::GetAttributeValue(int index)
{
        if(index<=AttributeCount&&index>=0)
        {
                return attribute


.AttributeValue->Des();
        }
}
int CXMLElement::GetAttributeCount()
{
        return AttributeCount;
}

XMLData::XMLData()
{
        rootNode=NULL;
        element_count=0;
}
XMLData::~XMLData()
{
}
void XMLData::ConstructL()
{       
}
XMLData* XMLData::NewL()
{
        XMLData* self = XMLData::NewLC();
        CleanupStack::Pop();
        return self;
}
XMLData* XMLData::NewLC()
{
        XMLData* self = new ( ELeave ) XMLData();
        CleanupStack::PushL( self );
        self->ConstructL();
        return self;
}

void XMLData::AddL(CXMLElement *data)
{
        XMLNode *node=new XMLNode;
        node->dataPtr=data;
        node->next=NULL;
        if (rootNode==NULL)
        {
                rootNode=node;
        }
        else
        {
                XMLNode *ptr;
                for (ptr=rootNode;ptr->next;ptr=ptr->next);
                ptr->next=node;
        }
        element_count++;
}
CXMLElement *XMLData::Item(int pos)
{
        if (pos>=0 && pos<=element_count && element_count>=0) {
                XMLNode *ptr;
                int i=0;
                for (ptr=rootNode;i<pos && ptr->next;ptr=ptr->next,i++);
                return ptr->dataPtr;
        } else {
                return NULL;
        }
}

int XMLData::Count()
{
        return element_count;
}

Thank you very much in advance...

please help me friends.

Netrananda.


Sat, 2008-03-08 12:35
Joined: 2005-11-20
Forum posts: 1157
Re: USER 44

The HBufC8::NewLC method that you use in AddAttributeL pushes the new buffer on the cleanup stack, but I can't find where you pop it.

Which line crashes anyway? The debugger should show you this.


René Brunner

Sat, 2008-03-08 13:06
Joined: 2006-12-19
Forum posts: 72
Re: USER 44

Please do the required correction in the above code.
because
i used HBufC8::NewL insted of HBufC8::NewLC but still same errors comes.

descripter is very confusing concept of the Symbian C++ i think.

Thanks again.

Sat, 2008-03-08 13:20
Joined: 2005-11-20
Forum posts: 1157
Re: USER 44

Well, that NewLC thing certainly is wrong and needs correction, one way or the other. If it still does not run with NewL() instead of NewLC(), there must be other errors. I just don't see it, because I cannot run the code.

Say again, which line crashes? That's a valuable hint.

If you don't know because you don't use a debugger so far, here my standard advice: Learn how to debug. No chance without it.


René Brunner

Mon, 2008-03-10 06:35
Joined: 2006-04-19
Forum posts: 134
Re: USER 44

Hi

From SDK:
This panic is raised by the Free() and FreeZ() member functions of an RHeap. It is caused when the cell being freed overlaps the next cell on the free list (i.e. the first cell on the free list with an address higher than the one being freed).

From your code:

ElementName = HBufC8::NewLC(EName.Length()); //SetElementNameL(const TDesC8& EName)

attribute[AttributeCount].AttributeName = HBufC8::NewLC(AName.Length()); //AddAttributeL
attribute[AttributeCount].AttributeValue = HBufC8::NewLC(AValue.Length());

You are pushing the buffer into stack thrice and never popped out .Hope it'll give u a hint otherwise as rbrunner suggested you should debug your code.this is the best way to find out bugs. I'll suggest you one thing also do take care of stack at time of coding as it can be the reason of the serious problem if u miss a single point.
Regards,
Isha


"To the question of your life , you are the only Answer. To the problems of your life,you are the only Solution".

  • Login to reply to this topic.