Rule: For every call to malloc(…) you must have one call to free(…). Rule: Do not free(…) the same buffer more than once. malloc(…) returns the address of a buffer on the heap. free(…) takes the address of a buffer on the heap. free(…) takes the address that malloc(…) returned. Rule: Do not access memory in the heap buffer after it has been freed.