我有这段代码:
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) {
char* threadID = XMLString::transcode(
attrs.getValue(emptyStr, tidStr));
long int tid = strtol(threadID, &threadID, 16); //hex
if (tid != current) {
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);
}
令我困惑的是需要注释掉 threadID 的释放——如果我不立即删除坏指针时代码会出现段错误。但是由于 threadID 是 XMLString::transcode 的结果,它肯定应该被释放吗?