C memory leak problem help# Programming - 葵花宝典
z*o
1 楼
请教这段代码为什么不能FREE malloc 分配的内存,老是泄漏?
void sp_free(sp_t* a)
{
struct sp_cell *prev, *tmp;
int i;
for (i=0; i < a->num_rows; i++)
{
prev = a->rows[i];
if (prev != NULL)
{
tmp = prev->next;
while(tmp != NULL)
{
prev = tmp;
tmp = prev->next;
free(prev);
}
}
}
for (i=0; i < a->num_cols; i++)
{
prev = a->cols[i];
if (prev != NULL)
void sp_free(sp_t* a)
{
struct sp_cell *prev, *tmp;
int i;
for (i=0; i < a->num_rows; i++)
{
prev = a->rows[i];
if (prev != NULL)
{
tmp = prev->next;
while(tmp != NULL)
{
prev = tmp;
tmp = prev->next;
free(prev);
}
}
}
for (i=0; i < a->num_cols; i++)
{
prev = a->cols[i];
if (prev != NULL)