malloc-tutorial
malloc-tutorial copied to clipboard
exersise 2 solution
We could also create the rest of the solutions in the same format (as a diff from the original) to avoid repeated code.
Offtopic: Thank you so much for the tutorial. The code is so beautiful that it demonstrates that C is the best language for this type of tasks.
Evidence (thanks to villoc ):
The program used was:
void *ptr1 = malloc(29);
free(ptr1);
malloc(1);
malloc(5);
int *ptr2 = malloc(3);
free(ptr2);
malloc(4);
And executed this way:
$ patch -p1 < exersise_2_split.patch
patching file malloc.c
$ make
$ setarch x86_64 -R ltrace ./wrapper ./test-0 |& tail +6 | tee ltrace.out
malloc(29) = 0x555555559018
free(0x555555559018) = <void>
malloc(1) = 0x555555559018
malloc(5) = 0x55555555904d
malloc(3) = 0x555555559031
free(0x555555559031) = <void>
malloc(4) = 0x555555559031
+++ exited (status 0) +++
$ cat ltrace.out | /tmp/villoc/villoc.py --chronological --header=24 --round=1 --minsz=0 - - > /tmp/out.html