-3

On the below program, I need to call free() on Hash Table, List Elements and Unique words. I tried couple things but all either break the program or increases error messages. Some attempts are in comments and bold.

Does anyone know where and how to call free? Its confusing as pointers are involved.

h_ptr *htable;
int tsize;


void new_table(int size)
{
    tsize = size;
    htable = (h_ptr *) calloc(size, sizeof(h_ptr));
    if (!htable) {
    fprintf(stderr, "Couldn't allocate hash array, exiting\n");
    exit(1);
    }


    for(int i=0; i<size; i++)
      {
    htable[i]=NULL;
      }
}
4

1 回答 1

2

防止内存泄漏总是一样的。如果您分配了一些内存,请正确删除它。因此,如果您的函数在malloc()某处使用,也可以在某处写入free()以避免内存泄漏

于 2013-03-08T19:46:58.263 回答