有人能幫我找到我的內存泄漏嗎?我使用valgrind來檢查泄漏,我無法找到它報告的那些。謝謝!我的內存泄漏在哪裏?
bigint* bi_create(const char* charint)
{
int length = 0;
const char* temp;
int flag = 0;
temp = charint;
while(*charint != '\0')
{
length++;
charint++;
}
char chartoint[length];
charint = temp;
//printf("LENGTH = %d \n", length);
bigint* bi = malloc(sizeof(bigint));
bi->length = length;
int counter = 0;
bi->initialzero = 0;
while(*charint != '\0')
{
if(*charint == '0' && flag != 1)
{
(bi->initialzero)++;
}else
{
flag = 1;
}
chartoint[counter] = *charint;
// printf("CHARTOINT = %c \n", chartoint[counter]);
charint++;
counter++;
}
bi->data = atoi(chartoint);
printf("DATA = %d \n", bi->data);
// printf("INITIAL ZERO = %d \n", bi->initialzero);
return bi;
}
他說他用valgrind。 – Barmar 2012-08-12 04:47:37
你的代碼的其餘部分在哪裏? – TOC 2012-08-12 04:49:01
該功能可以肯定使用一些簡化。第一個while循環可以用'length = strlen(charint)'代替。在第二個while循環中,爲什麼要複製到圖表中?爲什麼不只是'bi-> data = atoi(charint)'? – Barmar 2012-08-12 04:58:35