emulator bug

Martin Bjorklund mbj@REDACTED
Mon Mar 18 09:48:02 CET 2002


There's a bug in the emu, r8 (and maybe r7; at least in the patched r7
we use): if you've had more than 1024 ports, and a driver calls
driver_exit, the link to the port in the connected process is not
removed.  This means that some bytes are leaked.

Attached is a program to reproduce the bug, and a patch to io.c for r8
which fixes the bug.


/martin
-------------- next part --------------
-module(d).
-compile(export_all).

d() -> d(1050).
d(N) ->
    spawn(?MODULE, dd, [N]).

dd(N) ->
    ddd(N),
    Links = length(element(2, erlang:process_info(self(), links))),
    io:format("BUG: ~p (~p links, ~p ports)\n",
	      [Links /= 0, Links, length(erlang:ports())]).

ddd(0) ->
    ok;
ddd(N) ->
    erl_epmd:port_please("foo", "localhost"),
    ddd(N-1).
-------------- next part --------------
*** otp_src_R8B-0.orig/erts/emulator/beam/io.c	Mon Mar 18 09:13:09 2002
--- otp_src_R8B-0/erts/emulator/beam/io.c	Mon Mar 18 09:10:08 2002
***************
*** 2602,2609 ****
  
      /* unlink port from connected */
      if ((rp = pid2proc(prt->connected)) != NULL)
!         del_link(find_link(&rp->links, LNK_LINK, prt->id,
!                            make_port2(THIS_NODE, ix), NIL));
  
      if (err == 0)
          return driver_failure_term(ix, am_normal, 0);
--- 2602,2608 ----
  
      /* unlink port from connected */
      if ((rp = pid2proc(prt->connected)) != NULL)
!         del_link(find_link(&rp->links, LNK_LINK, prt->id, NIL));
  
      if (err == 0)
          return driver_failure_term(ix, am_normal, 0);


More information about the erlang-questions mailing list