[erlang-patches] Reference count bugfix in erl_ddll

Jean-Sébastien Pédron <>
Wed Oct 11 15:25:09 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

erl_ddll may contain a bug with reference count, here is an example:

1. Load a port driver on node `node1':
()1> self().
<0.37.0>
()2> erl_ddll:load_driver("/path/to/libs", my_drv).
ok

2. Start another shell on this same node and load the same driver:
()1> self().
<0.44.0>
()2> erl_ddll:load_driver("/path/to/libs", my_drv).
ok

The purpose here is to have separate processes using the same driver.
This can be verified by looking at the ddll_server status on `node1':
()3> sys:get_status(ddll_server).
{status,<0.46.0>,
        {module,gen_server},
        [[{'$ancestors',[<0.37.0>]},
          {'$initial_call',{gen,init_it,
                                [gen_server,
                                 <0.37.0>,
                                 self,
                                 {local,ddll_server},
                                 erl_ddll,
                                 [],
                                 []]}}],
         running,
         <0.46.0>,
         [],
         [ddll_server,
          {#Port<0.101>,[{my_drv,[{<0.44.0>,1},{<0.37.0>,1}]}]},
          erl_ddll,
          infinity]]}
We can see shell's PID listed with `my_drv'.

3. Now another shell on this same node and load the driver a third time:
()1> self().
<0.55.0>
()2> erl_ddll:load_driver("/path/to/libs", my_drv).
ok

If we look again at ddll_server's status:
()4> sys:get_status(ddll_server).
{status,<0.46.0>,
        {module,gen_server},
        [[{'$ancestors',[<0.37.0>]},
          {'$initial_call',{gen,init_it,
                                [gen_server,
                                 <0.37.0>,
                                 self,
                                 {local,ddll_server},
                                 erl_ddll,
                                 [],
                                 []]}}],
         running,
         <0.46.0>,
         [],
         [ddll_server,
          {#Port<0.101>,[{expat_drv,[{<0.55.0>,1},{<0.37.0>,1}]}]},
          erl_ddll,
          infinity]]}
The second shell (<0.44.0>) isn't listed anymore.

The consequence is that if the first and the last unload the driver, the
library `my_drv.so' will be unloaded and shell #2 port driver will
become unusable.

Attached is a patch that should fix this.

- --
Jean-Sébastien Pédron
Meetic Corp.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFLPC1a+xGJsFYOlMRAqhtAKDHqFf4FL2bRrWtrlqYqa8waXFFLgCfe8g6
1NKNvNQJzZIzFN+HUGw9q7s=
=5JqK
-----END PGP SIGNATURE-----



More information about the erlang-patches mailing list