If you malloc and never free, the program leaks. free once, then do not touch the pointer.
The correct life of a heap block is malloc, use, free. A leak is forgetting free (or losing the pointer). This lesson also sets p = NULL after free so you are less likely to use or free it again.
live
print 7
dead
done
Each step highlights the matching C line. Program output appears only when a line that prints actually runs.
Five questions. Pick one answer each, then Check answers. The correct choice turns green.
1. Correct order is:
Use then free.
2. After free, p = NULL helps because:
Dangling pointer hygiene.
3. A leak is:
Lost block.
4. free(NULL) is:
Safe.
5. Another kind, realloc(p, bigger):
May relocate.