diff --git a/c_src/async_nif.h b/c_src/async_nif.h index 30ad669..979b1b7 100644 --- a/c_src/async_nif.h +++ b/c_src/async_nif.h @@ -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; diff --git a/src/riak_kv_wterl_backend.erl b/src/riak_kv_wterl_backend.erl index 1de076f..8492e7b 100644 --- a/src/riak_kv_wterl_backend.erl +++ b/src/riak_kv_wterl_backend.erl @@ -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) ->