Salve a tutti.

Ho un problema che non riesco proprio a risolvere.

Nel mio programma devo gestire delle liste e poi deallocarle. Il problema è che il programma gira all'infinito, e ad ogni giro, ho un incremento di ram utilizzata di circa 4kb. Il mio obiettivo è portarlo a zero.

Ecco il codice di gestione delle liste.

--> dichiarazione strutture <--

/*strutture e metodi per gestione righe della tabella di transformazione*/
typedef struct RowTransformation{
char id[20];
char tab[51];
char field[51];
int type;
} RowTransformation;

struct TransformationList{
RowTransformation *row;
struct TransformationList *next;
};


--> inserimento in coda <--
void aggiungiRowTransformationInCoda(struct TransformationList *TList,struct RowTransformation *newRow)
{

if(TList == NULL)
{
//primo elemento
TList = (struct TransformationList *)malloc(sizeof(struct TransformationList));
TList->row=newRow;
TList->next=NULL;
// return TList;
} //TList==NULL
else{
struct TransformationList *temp=(struct TransformationList *)malloc(sizeof(struct TransformationList));
if(temp!=NULL) {
temp=TList;
//vado all'ultimo elemento
while(temp->next)
{
temp=temp->next;
}

//aggiungo elemento in coda
struct TransformationList *nuovo=(struct TransformationList*)malloc(sizeof(struct TransformationList));
if(nuovo!=NULL)
{
nuovo->row=newRow;
nuovo->next=NULL;
temp->next=nuovo;
} //nuovo
}//temp
}//else

// return (TList);
}


--> dealloco lista <--

/*dealloca memoria*/
int clearListaTransformation(struct TransformationList* p)
{
//printf("Clear Lista Transformation\n");
LogWrite("Clear Lista Transformation.");

int count=0;
struct TransformationList* aus=p;

if (p == NULL)
{
printf (" Nessuna riga presente in Lista Transformation\n");
} else { // ELSE

while (p != NULL)
{ // WHILE - OPEN
count++;
aus=p;
p=aus->next;

struct RowTransformation *r=(struct RowTransformation*)malloc(sizeof(struct RowTransformation));
r=aus->row;
free(r);

free(aus);
} // WHILE - CLOSE
free(p);
}//else
return count;
}


Credo che il problema sia nell'inserimento..ma non ne sono sicura.
Mi scuso, ma non ho potuto postare tutto il codice in cui sono utilizzate queste funzioni perchè sono spalmate in diversi files.

Grazie a chiunque mi saprà dare una mano.

Ciao ciao