【发布时间】:2010-07-16 04:13:20
【问题描述】:
我有这个代码:
void getStringWithTag(char* pFile, long sizeSound, char* tag, char* ret, float* currentPos){
char* tagCopy;
tagCopy = (char*)malloc(256 * sizeof(char));
int totalLen = 0;
int tempLen = 0;
memset(tagCopy, 0, 256);
memset(ret, 0, 128);
pFile += ((int)*currentPos);
while (totalLen+(*currentPos) < sizeSound) {
if (*pFile == '<') {
pFile += 5;
totalLen += 5;
while(*pFile != '>'){
*tagCopy = *pFile;
tagCopy++;
pFile++;
totalLen++;
tempLen++;
}
tagCopy -= tempLen;
tempLen = 0;
if (strcmp(tagCopy, tag) == 0) {
pFile++;
totalLen++;
while (*pFile != '<') {
*ret = *pFile;
ret++;
pFile++;
totalLen++;
tempLen++;
}
ret -= tempLen;
*currentPos += totalLen;
tagCopy = NULL;
free(tagCopy);
return;
}else{
memset(tagCopy, 0, 256);
}
}
pFile++;
totalLen++;
}
tagCopy = NULL;
free(tagCopy);
*currentPos = sizeSound;
ret = NULL;
}
这显然给了我“tagCopy”的内存泄漏。 谁能告诉我为什么?我以为我把它写得很好,但这是我唯一出现内存泄漏的地方。
谢谢。
【问题讨论】:
标签: c ipad memory-leaks