malloc-tutorial icon indicating copy to clipboard operation
malloc-tutorial copied to clipboard

exersise 2 solution

Open isidroas opened this issue 1 year ago • 1 comments

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.

isidroas avatar Nov 26 '24 14:11 isidroas

Evidence (thanks to villoc ): 2024-12-05-132725_crop

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

isidroas avatar Dec 05 '24 12:12 isidroas