A: 

I think yes ...

When you have finished using a portion of menory , we should free() it.This allows the memory freed to be used for some other purposes...like further malloc() calls.

Free takes a pointer to the memory as an argument and frees the memory to which the pointer refers to...

Hope this helps ... :)

ravi
-1: This doesn't answer the question. bodacydo was not asking, should he free memory. He was asking, should he set the pointers to NULL after freeing it.
Platinum Azure
+4  A: 

This is considered a good practice by some because it prevents you from accidentally accessing the memory after it has been free()ed.

Darron
After reading the answers, I found it to be a bad practice - I am hiding errors of double-free! How can this possibly be a good practice?
bodacydo
Actually, it doesn't automatically prevent you from accessing it, but you can (and should) always check against NULL pointers, but you can't tell if a not-NULL pointer is valid. Therefore it is good practice.
cypheon
I am not yet convinced that it's a good practice.
bodacydo
+8  A: 

While it can't hurt, it doesn't always help. The issue to consider is that it's easy for there to be multiple copies of the pointer and most likely you are only going to set a single one to NULL. The classic example of where it doesn't help at all is:

void free_graph(graph *g)
{
    ...
    free(g);
    g = NULL;  // not useful in this context
}

The problem here is that you are only setting the pointer that is local to free_graph to NULL and the pointer is held by the caller of free_graph will still have it's original value.

R Samuel Klatchko
+2  A: 

Bad practice vote from me. If you do want to assign a value, set it to (void*)0xdeadbeef. Check what your CRT can do first though. A decent debug allocator will set freed memory to a pattern that's likely to cause a bomb when the pointer is used after it was freed. Albeit that it isn't guaranteed. But then not changing the pointer value is the better (and faster) solution.

Hans Passant