c++ - Memory leak caused by removing value from vector -


A few days ago I asked for help to remove the value of the index rather than the value from a vector)

I was able to get a solution to compile with the help of Angav, the solution has been marked as 'Answer' in the thread.

However, when executing my program with this fix, my program unexpectedly stops, and when it runs through a debugger, it seems that fixes cause the memory leak Is there any insight on how this can be done?

Again, my straight uses me to find the value that I am trying to remove:

  Struct isUnderScore {bool operator ()) (char c) {return C == '_'; }};  

I can use it on the string so that the deleted phrases can be easily liked:

  string.erase (remove_if (string.begin) (), String.end (), IsUnderScore ()), string.end ());  

But when it was used on a vector, I had compiler problems, which were solved like this:

  vector.erase (std) :: remove (vector.begin) (), Vector.end (), std :: string ("_")));  

And now I get a memory leak.

Edit: There is a copy of the error given by gdb.

  Programmable signals SIGSEGV, Segmentation error 0x00002aaaab917ee8 std :: string :: _ RIP :: _ M_is_leaked ()  

This code contains a potential problem:

  vector.erase (std :: removal (vector.begin (), vector End (), std :: string ("_")));  

If std :: remove does not match any element vector.end () . end () Trash the eraser is undefined and the result of a segfault can be.

I think you want to erase the std :: vector :: two logic argument because it can control an empty range std :: Remove matches several elements ...

  vector.erase (std :: removal (vector.begin ()), vector.end (), std :: string ("_"), Vector.end ());  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -