shared_ptr<void> t(new char[num])
means memory leak?
If so, what is the correct practice in this case.
should I use shared_array<> instead?
I’m editing the bytes pointed by ‘t’ manually for later transfer in a TCP Stream.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, it means undefined behavior. (Which could have any symptom, including memory leak.) The call to
deletemust match the call tonew. Yours doesn’t. You allocate withnew[]but destroy withdelete.There are two easy choices. You can use
shared_array:Or, you could use a
shared_ptrto astd::vector:EDIT: Thanks to @Dennis Zickefoose for gently pointing out an error in my thinking. Parts of my answer are rewritten.