Re: [classad-users] ClassAdCollections and InitialisefromLog


Date: Wed, 07 Dec 2005 21:17:52 -0600
From: Alain Roy <roy@xxxxxxxxxxx>
Subject: Re: [classad-users] ClassAdCollections and InitialisefromLog
You have two errors. They aren't your fault--Collections are poorly documented.

In addition, I have on additional suggestion.

       ClassAdCollection *cac=new ClassAdCollection(true);

I recommend not using the caching feature unless you want to live on the edge. It has barely been tested, and isn't needed unless you have too many ClassAds to keep in memory.

       add_classad=cac->AddClassAd("C2",mad2);
       cout<<"add_classad="<<add_classad<<"C2 Added"<<endl;
       add_classad=cac->AddClassAd("V1",mad3);
       cout<<"add_classad="<<add_classad<<"V1 Added"<<endl;
       add_classad=cac->AddClassAd("J1",jad);
       cout<<"add_classad="<<add_classad<<"J1 Added"<<endl;

       add_classad=cac->AddClassAd("C3",mad2);

Once you add a ClassAd to a collection, you no longer own the pointer to it. The collection owns it. You should not delete it, corrupt it, or give it to anyone else. In particular, you should not insert it into a collection twice. This was the cause of your segmentation fault: you inserted mad2 twice.

       cout<<"DISPLAY VIEW INFO"<<endl;
       ClassAd *c=new ClassAd();
       cac->GetViewInfo("resource",c);

GetViewInfo will create a new ClassAd and place it into c. You therefore have lost the pointer to the new ClassAd you created, and it will be leaked. This didn't cause your crash, but it is a bug.

I hope this helps.

-alain


[← Prev in Thread] Current Thread [Next in Thread→]