views:

226

answers:

2

It looks like I have a memory leak when I try to initializ an array of pointers. This my code:

void initLabelTable(){
    register int i;
    hashNode** hp;
    labelHashTable = (hashNode**) malloc(HASHSIZE*sizeof(hashNode*));
    hp = labelHashTable;
    for(i=0; i<HASHSIZE; i++) {
        *(hp+i) = NULL;
    }
}

Any idea?

+1  A: 

No, this function by itself doesn't leak any memory. It allocates memory for labelHashTable, which, according to it's name, is what it's supposed to do.

Make sure that the memory pointed to by labelHashTable is freed once you're finished using it, else you will have a memory leak there. Also don't call initLabelTable() repeatedly without freeing labelHashTable before each subsequent call.

sth
A: 
DoronS