Reusing closed cursors is bad for your health (SEGV), don't do that.
Also a bit of paranoia, bzero after all enif_alloc calls.
This commit is contained in:
parent
1962640382
commit
456129e7f3
2 changed files with 12 additions and 10 deletions
|
@ -92,6 +92,7 @@ struct async_nif_worker_info {
|
|||
return enif_make_tuple2(env, enif_make_atom(env, "error"), \
|
||||
enif_make_atom(env, "enomem")); \
|
||||
} \
|
||||
bzero(req, sizeof(struct async_nif_req_entry)); \
|
||||
copy_of_args = (struct decl ## _args *)enif_alloc(sizeof(struct decl ## _args)); \
|
||||
if (!copy_of_args) { \
|
||||
fn_post_ ## decl (args); \
|
||||
|
@ -286,6 +287,7 @@ async_nif_load(void)
|
|||
async_nif = enif_alloc(sizeof(struct async_nif_state));
|
||||
if (!async_nif)
|
||||
return NULL;
|
||||
bzero(async_nif, sizeof(struct async_nif_state));
|
||||
STAILQ_INIT(&(async_nif->reqs));
|
||||
async_nif->shutdown = 0;
|
||||
|
||||
|
@ -309,6 +311,7 @@ async_nif_load(void)
|
|||
for (i = 0; i < num_worker_threads; i++) {
|
||||
struct async_nif_worker_info *wi;
|
||||
wi = enif_alloc(sizeof(struct async_nif_worker_info)); // TODO: check
|
||||
bzero(wi, sizeof(struct async_nif_worker_info));
|
||||
wi->async_nif = async_nif;
|
||||
wi->worker = &async_nif->worker_entries[i];
|
||||
wi->worker_id = i;
|
||||
|
|
|
@ -294,21 +294,20 @@ drop(#state{connection=Connection, table=Table}=State) ->
|
|||
-spec is_empty(state()) -> boolean().
|
||||
is_empty(#state{is_empty_cursor=Cursor}) ->
|
||||
wterl:cursor_reset(Cursor),
|
||||
try
|
||||
not_found =:= wterl:cursor_next(Cursor)
|
||||
after
|
||||
ok = wterl:cursor_close(Cursor)
|
||||
case wterl:cursor_next(Cursor) of
|
||||
not_found -> true;
|
||||
_ -> false
|
||||
end.
|
||||
|
||||
%% @doc Get the status information for this wterl backend
|
||||
-spec status(state()) -> [{atom(), term()}].
|
||||
status(#state{status_cursor=Cursor}) ->
|
||||
wterl:cursor_reset(Cursor),
|
||||
try
|
||||
Stats = fetch_status(Cursor),
|
||||
[{stats, Stats}]
|
||||
after
|
||||
ok = wterl:cursor_close(Cursor)
|
||||
case fetch_status(Cursor) of
|
||||
{ok, Stats} ->
|
||||
Stats;
|
||||
_ ->
|
||||
[]
|
||||
end.
|
||||
|
||||
%% @doc Register an asynchronous callback
|
||||
|
@ -493,7 +492,7 @@ from_index_key(LKey) ->
|
|||
%% @private
|
||||
%% Return all status from wterl statistics cursor
|
||||
fetch_status(Cursor) ->
|
||||
fetch_status(Cursor, wterl:cursor_next_value(Cursor), []).
|
||||
{ok, fetch_status(Cursor, wterl:cursor_next_value(Cursor), [])}.
|
||||
fetch_status(_Cursor, not_found, Acc) ->
|
||||
lists:reverse(Acc);
|
||||
fetch_status(Cursor, {ok, Stat}, Acc) ->
|
||||
|
|
Loading…
Reference in a new issue