Separate lifetime repairs from clean-run claims

A single-threaded C program executes the following fragment. Assume the required declarations are present, allocation succeeds, and sizeof(int) is 4 bytes.


C
int *p = malloc(3 * sizeof *p);
if (p == NULL) return;
p[0] = 27;
free(p);
printf("%d\n", p[0]);


Memcheck reports an invalid read of size 4 inside the 12-byte block that was freed by free(p). A separate global cache is reported as 64 bytes still reachable. After a proposed repair, the original input produces no reported errors. Which statements are supported? Select all that apply.

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More GDB & Valgrind Questions: