Hi Adrian,
you are invoking strtol specifying the threadID variable as the second argument; this argument will be overwritten to point to the first character that doesn't belong to the string representation of a number. So, calling XMLString::release on this will treat that value as the beginning of a memory buffer, but as it is no more true, the memory manager of your OS will complain. Define a new char* variable and use that in the call to strtol, or specify NULL

Alberto

Il 09/11/13 21:56, Adrian Mcmenamin ha scritto:
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