If you want to understand the memory usage, don't use top. Use the free open source program https://github.com/vmware/chap (disclaimer: I am the original developer).
Just gather a live core before the program finishes, for example by running gcore, then type:
chap your-core-file-name
Then you can do things like:
count leaked
list leaked
count used
count free
....
Here is an example using your program, gathering the core after 30 seconds:
-bash-4.1$ ./q53633998 &
[1] 18014
-bash-4.1$ sleep 30
gcore 18014
-bash-4.1$ gcore 18014
0x00000030ed6aca20 in __nanosleep_nocancel () at ../sysdeps/unix/syscall- template.S:82
82 T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
Saved corefile core.18014
-bash-4.1$ ~/public_html/chap core.18014
chap> count used
36 allocations use 0x9120 (37,152) bytes.
chap> count free
1 allocations use 0x17db0 (97,712) bytes.
chap> count leaked
35 allocations use 0x8d18 (36,120) bytes.
chap> count anchored
1 allocations use 0x408 (1,032) bytes.
chap> list anchored
Used allocation at 19d4e40 of size 408
1 allocations use 0x408 (1,032) bytes.
chap> explain 19d4e40
Address 19d4e40 is at offset 0 of
an anchored allocation at 19d4e40 of size 408
Allocation at 19d4e40 appears to be directly anchored from at least one stack.
Address 0x7ffc88570270 is on the live part of the stack for thread 1.
Stack address 7ffc88570270 references 19d4e40
chap> list leaked
Used allocation at 19cc010 of size 408
Used allocation at 19cc420 of size 408
Used allocation at 19cc830 of size 408
Used allocation at 19ccc40 of size 408
Used allocation at 19cd050 of size 408
Used allocation at 19cd460 of size 408
Used allocation at 19cd870 of size 408
Used allocation at 19cdc80 of size 408
Used allocation at 19ce090 of size 408
Used allocation at 19ce4a0 of size 408
Used allocation at 19ce8b0 of size 408
Used allocation at 19cecc0 of size 408
Used allocation at 19cf0d0 of size 408
Used allocation at 19cf4e0 of size 408
Used allocation at 19cf8f0 of size 408
Used allocation at 19cfd00 of size 408
Used allocation at 19d0110 of size 408
Used allocation at 19d0520 of size 408
Used allocation at 19d0930 of size 408
Used allocation at 19d0d40 of size 408
Used allocation at 19d1150 of size 408
Used allocation at 19d1560 of size 408
Used allocation at 19d1970 of size 408
Used allocation at 19d1d80 of size 408
Used allocation at 19d2190 of size 408
Used allocation at 19d25a0 of size 408
Used allocation at 19d29b0 of size 408
Used allocation at 19d2dc0 of size 408
Used allocation at 19d31d0 of size 408
Used allocation at 19d35e0 of size 408
Used allocation at 19d39f0 of size 408
Used allocation at 19d3e00 of size 408
Used allocation at 19d4210 of size 408
Used allocation at 19d4620 of size 408
Used allocation at 19d4a30 of size 408
35 allocations use 0x8d18 (36,120) bytes.
chap> list free
Free allocation at 19d5250 of size 17db0
1 allocations use 0x17db0 (97,712) bytes.
chap>
That last "free" allocation is the tail of a block of memory that was allocated during the first malloc call and gradually carved up as subsequent malloc calls were made.
Of course there are other tools out there (e.g. valgrind) that work differently by instrumenting the process but if you want a tool that can analyze memory usage of a process without changing the way the process is run, chap is a good choice.