// Pantea Aria // Memory Leak Example (Lost Pointer) // Complete the TODO sections below // (Memory is allocated twice but only one freed) // use "dcc --leak-check program_name.c -o program" to see the error message #include #include int main(void) { // TODO 1: // Allocate memory for one integer int *ptr = malloc(sizeof(int)); // TODO 2: // Store the value 10 in the allocated memory *ptr = 10; // TODO 3: // Allocate NEW memory to ptr again ptr = malloc(sizeof(int)); // TODO 4: // Explain in a comment: // What happened to the first allocated memory? // TODO 5: // Free the memory currently pointed to by ptr free (ptr); return 0; }