The heap is the region of a running program’s memory from which blocks are handed out on request while it runs. Dynamic allocation is the obtaining of such a block: malloc(n) returns the address of a new block of n bytes, or the null pointer if it cannot. The block exists until the program passes its address to free, whatever functions return in between.
main’s frame; the blocks they hold the addresses of live on the heap. The first block has been freed: squares still holds its address, but the block is no longer the program’s.f ends when f returns; a block that f obtains from malloc lasts until some part of the program frees it, possibly far from f. The programmer, not the call structure, chooses when.