Skip to content

Commit

Permalink
Fix refcount of resources
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed Jan 28, 2025
1 parent 96793bf commit b539e1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/libAtomVM/dist_nifs.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ static term nif_erlang_setnode_3(Context *ctx, int argc, term argv[])
if (UNLIKELY(memory_ensure_free_opt(ctx, TERM_BOXED_RESOURCE_SIZE, MEMORY_CAN_SHRINK) != MEMORY_GC_OK)) {
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
}
return term_from_resource(conn_obj, &ctx->heap);
term result = enif_make_resource(erl_nif_env_from_context(ctx), conn_obj);
enif_release_resource(conn_obj);
return result;
}

static term nif_erlang_dist_ctrl_get_data_notification(Context *ctx, int argc, term argv[])
Expand Down Expand Up @@ -633,6 +635,7 @@ term dist_send_message(term target, term payload, Context *ctx)
term_put_tuple_element(autoconnect_message, 0, CONNECT_ATOM);
term_put_tuple_element(autoconnect_message, 1, term_from_atom_index(node_atom_index));
term_put_tuple_element(autoconnect_message, 2, term_from_resource(new_conn_obj, &heap));
enif_release_resource(new_conn_obj);

globalcontext_send_message(ctx->global, term_to_local_process_id(net_kernel_proc), autoconnect_message);
END_WITH_STACK_HEAP(heap, ctx->global)
Expand Down
3 changes: 1 addition & 2 deletions src/libAtomVM/otp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ static term socket_make_select_notification(struct SocketResource *rsrc_obj, Hea
term_put_tuple_element(notification, 0, DOLLAR_SOCKET_ATOM);
term socket_tuple = term_alloc_tuple(2, heap);
term_put_tuple_element(socket_tuple, 0, term_from_resource(rsrc_obj, heap));
struct RefcBinary *rsrc_refc = refc_binary_from_data(rsrc_obj);
refc_binary_increment_refcount(rsrc_refc);
term socket_ref;
if (rsrc_obj->socket_ref_ticks == 0) {
socket_ref = UNDEFINED_ATOM;
Expand Down Expand Up @@ -1720,6 +1718,7 @@ static term nif_socket_listen(Context *ctx, int argc, term argv[])
static term make_accepted_socket_term(struct SocketResource *conn_rsrc_obj, Heap *heap, GlobalContext *global)
{
term obj = term_from_resource(conn_rsrc_obj, heap);
enif_release_resource(conn_rsrc_obj);

term socket_term = term_alloc_tuple(2, heap);
uint64_t ref_ticks = globalcontext_get_ref_ticks(global);
Expand Down

0 comments on commit b539e1c

Please sign in to comment.