strlen
will give you the length of the C string not the size of the buffer.
The length of a C string is determined by the terminating null-character: a C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself). So 0 is the right answer.
However the malloc()
routine will hold the size of the allocation you made so when you free() it, it frees the right amount of space.
It is up to you to track the size of the memory if you need it (see Using sizeof with a dynamically allocated array and Is it possible to find the Memory Allocated to the Pointer, without searching for the malloc statement).
With gcc / glibc you have the malloc_usable_size function (not included in POSIX.x / C90 / C99 / C11):
#include <malloc.h>
size_t malloc_usable_size (void *ptr);
that returns the number of usable bytes in the block pointed to by ptr
.