【发布时间】:2013-11-09 17:07:49
【问题描述】:
我有这段代码:
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 的释放——如果我不这样做,代码会立即在删除坏指针时出现 seg 错误。但是由于 threadID 是 XMLString::transcode 的结果,它肯定应该被释放吗?
【问题讨论】: