[Bug c++/60371] std::vector::emplace_back

2014-03-02 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60371

--- Comment #5 from Jonathan Wakely redi at gcc dot gnu.org ---
(In reply to Дилян Палаузов from comment #3)
 Indeed, adding
 
   z (const z x) { var = strdup (x.var); }
 
 solves the problem.  However, I don't understand how that y.clear();
 between the y.emplace_back() in the original program avoids the double free.

In the original program the vector is resized on the second insertion, so the
existing element must be copied to the new storage (which results in a shallow
copy of the malloc'd memory, and leads to a double free).

When you clear the vector it doesn't need to be resized, so no element is
copied, so no shallow copy.

[Bug c++/60371] std::vector::emplace_back

2014-02-28 Thread dilyan.palauzov at aegee dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60371

Дилян Палаузов dilyan.palauzov at aegee dot org changed:

   What|Removed |Added

 CC||dilyan.palauzov at aegee dot 
org

--- Comment #1 from Дилян Палаузов dilyan.palauzov at aegee dot org ---
Created attachment 32236
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=32236action=edit
Resulting binary on my system

[Bug c++/60371] std::vector::emplace_back

2014-02-28 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60371

--- Comment #2 from Andrew Pinski pinskia at gcc dot gnu.org ---
This sounds like there is a copy constructor happening and you don't have a
copy constructor defined so it is a direct assignment which means you will get
a double free.


[Bug c++/60371] std::vector::emplace_back

2014-02-28 Thread dilyan.palauzov at aegee dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60371

--- Comment #3 from Дилян Палаузов dilyan.palauzov at aegee dot org ---
Indeed, adding

  z (const z x) { var = strdup (x.var); }

solves the problem.  However, I don't understand how that y.clear(); between
the y.emplace_back() in the original program avoids the double free.

[Bug c++/60371] std::vector::emplace_back

2014-02-28 Thread dilyan.palauzov at aegee dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60371

Дилян Палаузов dilyan.palauzov at aegee dot org changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #4 from Дилян Палаузов dilyan.palauzov at aegee dot org ---
I have to put here some comment, despite the comment I posted on the bug report
some minutes ago.  Otherwise the system does not permit me to change the status
from UNCONFIRMED to RESOLVED/INVALID.