You have memory leaks when you allocate memory or assume responsibility for previously allocated memory and fail to de-allocate this memory when you no longer need it.
In your example you're receiving pointers to already allocated structures but you are not assuming responsibility for freeing that memory.
In the case of c_str()
you're getting a pointer to the internal memory of the string. If that string falls out of scope and gets destroyed, that pointer is no longer valid. It does not need to be freed since you don't own it. There are likely other things that will invalidate your pointer, so you'll need to be very careful when using pointers like this.
A better way to write this is:
const char* chrarray = str.c_str();
There's no need to initialize the pointer to NULL
and then immediately re-write it to something else.
The second case describes what happens in a lot of old C libraries where they will return pointers to shared memory that you do not own. Some of these are not thread safe since all threads will refer to the same block, so read the documentation very carefully when you're receiving pointers. If you are to assume ownership of it, you will have to destroy using the correct method or you will leak.