Skip to content

Commit

Permalink
fix: check lib isn't closed while getopt global
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Oct 6, 2023
1 parent 56e9e45 commit 1284705
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion c_src/quicer_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
#include <msquichelper.h>

extern QuicerRegistrationCTX *G_r_ctx;
extern pthread_mutex_t MsQuicLock;

static ERL_NIF_TERM get_stream_opt(ErlNifEnv *env,
QuicerStreamCTX *s_ctx,
Expand Down Expand Up @@ -768,7 +769,14 @@ getopt3(ErlNifEnv *env,

if (IS_SAME_TERM(ATOM_QUIC_GLOBAL, ctx))
{
res = get_global_opt(env, NULL, eopt);
pthread_mutex_lock(&MsQuicLock);
// Get global option without using any ctx
// We are risking using a closed lib
if (MsQuic)
{
res = get_global_opt(env, NULL, eopt);
}
pthread_mutex_unlock(&MsQuicLock);
}
else if (enif_get_resource(env, ctx, ctx_stream_t, &q_ctx))
{
Expand Down

0 comments on commit 1284705

Please sign in to comment.