Permalink
Browse files

Do not release context and resources until they are terminated or clo…

…sed, respectively.
  • Loading branch information...
1 parent 578b6fc commit f3b0c8b46e81274241420d7fa67c8de4654eba51 @yrashk yrashk committed Mar 12, 2011
Showing with 5 additions and 2 deletions.
  1. +5 −2 c_src/erlzmq_nif.c
View
@@ -109,7 +109,6 @@ NIF(erlzmq_nif_context)
enif_mutex_unlock(handle->mutex);
ERL_NIF_TERM result = enif_make_resource(env, handle);
- enif_release_resource(handle);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), result);
}
@@ -138,7 +137,6 @@ NIF(erlzmq_nif_socket)
handle->socket = zmq_socket(ctx->context, _type);
ERL_NIF_TERM result = enif_make_resource(env, handle);
- enif_release_resource(handle);
return enif_make_tuple2(env, enif_make_atom(env, "ok"), result);
}
@@ -614,6 +612,9 @@ NIF(erlzmq_nif_close)
return enif_make_badarg(env);
}
+ enif_release_resource(socket);
+
+
if (-1 == zmq_close(socket->socket)) {
return enif_make_tuple2(env, enif_make_atom(env, "error"), enif_make_int(env, zmq_errno()));
} else {
@@ -642,6 +643,8 @@ NIF(erlzmq_nif_term)
zmq_send(ctx->ipc_socket, &msg, ZMQ_NOBLOCK);
zmq_msg_close(&msg);
+ enif_release_resource(ctx);
+
return enif_make_copy(env, recv.ref);
}

0 comments on commit f3b0c8b

Please sign in to comment.