210
35
int *stack = malloc(100 * sizeof(int));
36 }
37
38 int main(void) {
39
func();
40
return 0;
41 }
The memory allocation is moved to the function func(). A memory leak occurs
because the pointer to the newly allocated memory is a local variable on line 35, which is
lost when the function returns. Executing this program under Valgrind shows the results
in Listing 12-4.
Listing 12-4. Running Valgrind with code Listing 12-3
$ valgrind --leak-check=yes ./leak
==4413== Memcheck, a memory error detector
...
==4413== 400 bytes in 1 blocks are definitely lost in loss record 1 of 1
==4413==
at 0x4C2EB37: malloc (vg_replace_malloc.c:299)
==4413==
by 0x4004F7: func (leak.c:35)
==4413==
by 0x400507: main (leak.c:39)
==4413==
==4413== LEAK SUMMARY:
...
==4413== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Valgrind shows a loss of 400 bytes of memory allocated at leak.c:35. To learn more,
please visit the official Valgrind documentation (http://www.valgrind.org/docs/
manual/index.html).
Intel Inspector – Persistence Inspector
Intel Inspector – Persistence Inspector is a runtime tool that developers use to detect
programming errors in persistent memory programs. In addition to cache flush misses,
this tool detects
Chapter 12 Debugging persistent MeMory appliCations
35
int *stack = malloc(100 * sizeof(int));
36 }
37
38 int main(void) {
39
func();
40
return 0;
41 }
The memory allocation is moved to the function func(). A memory leak occurs
because the pointer to the newly allocated memory is a local variable on line 35, which is
lost when the function returns. Executing this program under Valgrind shows the results
in Listing 12-4.
Listing 12-4. Running Valgrind with code Listing 12-3
$ valgrind --leak-check=yes ./leak
==4413== Memcheck, a memory error detector
...
==4413== 400 bytes in 1 blocks are definitely lost in loss record 1 of 1
==4413==
at 0x4C2EB37: malloc (vg_replace_malloc.c:299)
==4413==
by 0x4004F7: func (leak.c:35)
==4413==
by 0x400507: main (leak.c:39)
==4413==
==4413== LEAK SUMMARY:
...
==4413== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Valgrind shows a loss of 400 bytes of memory allocated at leak.c:35. To learn more,
please visit the official Valgrind documentation (http://www.valgrind.org/docs/
manual/index.html).
Intel Inspector – Persistence Inspector
Intel Inspector – Persistence Inspector is a runtime tool that developers use to detect
programming errors in persistent memory programs. In addition to cache flush misses,
this tool detects
Chapter 12 Debugging persistent MeMory appliCations
