Home > Articles

A Word on C

  • Print
  • + Share This

Memory Leaks

Consider the following code fragment:

void someFunc( void )
{
  char *buf;

  buf = malloc( sizeof(char) * 256 );

   // do something

  return;
  // returning from the function results
  // in the frame being removed from the stack
}

The variable buf is local to someFunc and its value is lost when the function returns. The value, however, is a reference to memory allocated from the heap. If the function returns without an appropriate call to free, the memory can never be returned to the heap and is an illustration of a memory leak.

Finally, in our discussion of C syntax, style and convention are mechanisms for defining constants and macros within a program.

 

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.