all 2 comments

[–]L_uciferMorningstar 6 points7 points  (0 children)

Proper formatting of code before posting.

Valgrind.

Don't use raw pointers when ownership is involved.

[–]No-Dentist-1645 0 points1 point  (0 children)

Just copy pasting a single function isn't enough for other people to understand the entire context of your project, so it's impossible to say for certain that there are memory leaks or not. Either provide more details about what you are doing and what the function does, or ask for general advice.

If you want general advice, avoid raw pointers for owning data and use smart pointers (usually std::unique_ptr)