You have your
char *cstr = new char[data.size() + 1];
and the corresponding
delete[] cstr;
and these are implemented correctly (matching new[]
with delete[]
).
Nowhere else in your code do you allocate memory on the heap, and I don’t see anywhere that cstr is modified either.
All of these suggest that you don’t have a memory leak, or at least, not in the code you have submitted here.
If you think you have a memory leak, you should confirm it. Check the output from Valgrind (or a suitable alternative).