指向泄漏內存的函數的鏈接。我如何在這裏泄漏記憶,我每次分配記憶時都會釋放臨時記憶我不是嗎?
bool check(const char* word)
{
uint32_t len = strlen(word);
char currentWord[len+1];
for(int k = 0; k <= len; k++)
{
currentWord[k] = tolower((char)word[k]);
}
bool wordPresent = false;
uint32_t indexSize = (dict.wordCount/ITEMSPERBUCKET);
uint32_t index = (hashFunction(currentWord)%(indexSize-1));
dictNode *temp = malloc(sizeof(dictNode));
temp = chainedHashTable[index];
do
{
if (strncmp(temp->word, currentWord, temp->len) == 0)
{
wordPresent = true;
temp = NULL;
}
else
{
temp = temp->next;
}
}
while (temp != NULL);
free(temp);
return wordPresent;
}
任何幫助將不勝感激。
謝謝你的真棒快速反應,儘快找到解決方案! –