pmed / v8pp

Bind C++ functions and classes into V8 JavaScript engine
http://pmed.github.io/v8pp/
Other
898 stars 120 forks source link

class.hpp: C++ objects referenced with reference_external are still deleted when class_::destroy() is called #60

Closed scottd72 closed 7 years ago

scottd72 commented 7 years ago

Calling class_::referenceexternal "does not take ownership of the C++ pointer", but v8pp still deletes the C++ object when class::destroy is called, which is clearly not intended and leads to crashes due to double deletion.

The "destroy_after" parameter of class_singleton::wrap is only used to determine what callback is given to SetWeak, and isn't stored anywhere in the actual object registry, and so v8pp isn't actually keeping the necessary ownership information everywhere it needs to.

This affects both the shared_ptr branch and the main branch.

pmed commented 7 years ago

Hi @scottd72

I've fixed this issue by marking persistent handles for externally referenced objects as independent, and do not call destroy function for such objects.