[erlang-bugs] nif reload

Tony Rogvall tony@REDACTED
Mon May 26 18:32:33 CEST 2014


On 26 maj 2014, at 14:51, Sverker Eriksson <sverker.eriksson@REDACTED> wrote:

...

> Your niffy_upgrade-callback does
> 
> *priv_data = *old_priv_data;
> 
> which means your old and new module instances share the same data.
> You then free that data when the old instance is unloaded which leaves the new module with a dangling pointer.
> 
Got it.


> Either copy the data in niffy_upgrade or use reference counting in niffy_unload:
> 
> if (--ptr->n == 0) {
>    enif_free(ptr);
> }
> 
I had some problem understanding how to handle to old_priv_data in the the upgrade callback,
I thought unload always had to free the priv_data memory. Now I know better :-)

Thanks

/Tony


> 
> /Sverker, Erlang/OTP

"Installing applications can lead to corruption over time. Applications gradually write over each other's libraries, partial upgrades occur, user and system errors happen, and minute changes may be unnoticeable and difficult to fix"



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20140526/c6b40239/attachment.htm>


More information about the erlang-bugs mailing list