I have this code:

void startElement(const XMLCh* const uri, const XMLCh* const localname,
        const XMLCh* const qname, const Attributes& attrs) {
        char* temp = XMLString::transcode(localname);
        if (strcmp(temp, "thread") == 0) {
            const XMLCh* value = attrs.getValue(emptyStr, tidStr);
            char* threadID = XMLString::transcode(value);
            long int tid = strtol(threadID, &threadID, 16); //hex
            if (tid != current) {
                cout << "Previous thread instance had " << instructionCount
<< " instructions. ";
                instructionCount = 0;
                current = tid;
                cout << "Now made " << ++switches
                    << " thread switches and in thread ";
                cout << current;
                if (!(threadbitmap & 1 << tid - 1)) {
                    count++;
                    threadbitmap = threadbitmap |
                        1 << tid - 1;
                }
                cout << " of " << count << " threads." << endl;
            }
            //XMLString::release(&threadID);
        }
       XMLString::release(&temp);
}

The odd thing is that if I uncomment the XMLString::release(&threadID) then
the code blows up with an attempt to delete a bad pointer, but if I don't
the code appears to leak memory. What have I got wrong?

Adrian

Reply via email to