aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2014-11-25 14:33:04 +0100
committerSverker Eriksson <[email protected]>2015-01-21 16:13:53 +0100
commit25bb9b1ab01aeb23aee75730ba4cd3b12a19988b (patch)
tree862cbdec84acf5dea2e1e50f36b152da8d988103
parent3d90589d81e6569588fc197676c4d94c59e84f8e (diff)
downloadotp-25bb9b1ab01aeb23aee75730ba4cd3b12a19988b.tar.gz
otp-25bb9b1ab01aeb23aee75730ba4cd3b12a19988b.tar.bz2
otp-25bb9b1ab01aeb23aee75730ba4cd3b12a19988b.zip
erts: Fix port data memory allocation bug
for non-immediate port data >= sizeof(Eterm)*2 words.
-rw-r--r--erts/emulator/beam/erl_bif_port.c6
-rw-r--r--erts/emulator/test/port_SUITE.erl22
2 files changed, 17 insertions, 11 deletions
diff --git a/erts/emulator/beam/erl_bif_port.c b/erts/emulator/beam/erl_bif_port.c
index 2464da6d24..ab473c6a08 100644
--- a/erts/emulator/beam/erl_bif_port.c
+++ b/erts/emulator/beam/erl_bif_port.c
@@ -472,7 +472,7 @@ cleanup_old_port_data(erts_aint_t data)
ErtsPortDataHeap *pdhp = (ErtsPortDataHeap *) data;
size_t size;
ERTS_SMP_DATA_DEPENDENCY_READ_MEMORY_BARRIER;
- size = sizeof(ErtsPortDataHeap) + pdhp->hsize*(sizeof(Eterm) - 1);
+ size = sizeof(ErtsPortDataHeap) + (pdhp->hsize-1)*sizeof(Eterm);
erts_schedule_thr_prgr_later_cleanup_op(free_port_data_heap,
(void *) pdhp,
&pdhp->later_op,
@@ -508,7 +508,7 @@ erts_port_data_size(Port *prt)
}
else {
ErtsPortDataHeap *pdhp = (ErtsPortDataHeap *) data;
- return (Uint) sizeof(ErtsPortDataHeap) + pdhp->hsize*(sizeof(Eterm)-1);
+ return (Uint) sizeof(ErtsPortDataHeap) + (pdhp->hsize-1)*sizeof(Eterm);
}
}
@@ -550,7 +550,7 @@ BIF_RETTYPE port_set_data_2(BIF_ALIST_2)
hsize = size_object(BIF_ARG_2);
pdhp = erts_alloc(ERTS_ALC_T_PORT_DATA_HEAP,
- sizeof(ErtsPortDataHeap) + hsize*(sizeof(Eterm)-1));
+ sizeof(ErtsPortDataHeap) + (hsize-1)*sizeof(Eterm));
hp = &pdhp->heap[0];
pdhp->off_heap.first = NULL;
pdhp->off_heap.overhead = 0;
diff --git a/erts/emulator/test/port_SUITE.erl b/erts/emulator/test/port_SUITE.erl
index 78d76ccb64..8c904410b0 100644
--- a/erts/emulator/test/port_SUITE.erl
+++ b/erts/emulator/test/port_SUITE.erl
@@ -2297,8 +2297,10 @@ port_setget_data(Config) when is_list(Config) ->
Port = erlang:open_port({spawn_driver, "echo_drv"}, []),
NSched = erlang:system_info(schedulers_online),
+ HeapData = {1,2,3,<<"A heap binary">>,fun()->"This is fun"end,
+ list_to_binary(lists:seq(1,100))},
PRs = lists:map(fun(I) ->
- spawn_opt(fun() -> port_setget_data_hammer(Port,1) end,
+ spawn_opt(fun() -> port_setget_data_hammer(Port,HeapData,false,1) end,
[monitor, {scheduler, I rem NSched}])
end,
lists:seq(1,10)),
@@ -2316,13 +2318,17 @@ port_setget_data(Config) when is_list(Config) ->
PRs),
ok.
-port_setget_data_hammer(Port, N) ->
+port_setget_data_hammer(Port, HeapData, IsSet0, N) ->
Rand = random:uniform(3),
- try case Rand of
- 1 -> true = erlang:port_set_data(Port, atom);
- 2 -> true = erlang:port_set_data(Port, {1,2,3});
- 3 -> erlang:port_get_data(Port)
- end
+ IsSet1 = try case Rand of
+ 1 -> true = erlang:port_set_data(Port, atom), true;
+ 2 -> true = erlang:port_set_data(Port, HeapData), true;
+ 3 -> case erlang:port_get_data(Port) of
+ atom -> true;
+ HeapData -> true;
+ undefined -> false=IsSet0
+ end
+ end
catch
error:badarg ->
true = get(prepare_for_close),
@@ -2335,7 +2341,7 @@ port_setget_data_hammer(Port, N) ->
after 0 ->
ok
end,
- port_setget_data_hammer(Port, N+1).
+ port_setget_data_hammer(Port, HeapData, IsSet1, N+1).
wait_until(Fun) ->