Skip to content

Commit 2fa7e04

Browse files
committed
Fix nif to avoid segfault on upgrade
1 parent e3b2668 commit 2fa7e04

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

c_src/jsonx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,12 @@ reload(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info){
6262

6363
static int
6464
upgrade(ErlNifEnv* env, void** priv_data, void** old_priv_data, ERL_NIF_TERM load_info){
65+
*priv_data = *old_priv_data;
6566
return 0;
6667
}
6768
static void
6869
unload(ErlNifEnv* env, void* priv_data){
70+
enif_free(priv_data);
6971
return;
7072
}
7173

src/jsonx.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ init() ->
231231
Dir ->
232232
filename:join(Dir, ?LIBNAME)
233233
end,
234-
erlang:load_nif(So, [[json, struct, proplist, eep18, no_match], [true, false, null],
234+
ok = erlang:load_nif(So, [[json, struct, proplist, eep18, no_match], [true, false, null],
235235
[error, big_num, invalid_string, invalid_json, trailing_data, undefined_record]]).
236236

237237
not_loaded(Line) ->

0 commit comments

Comments
 (0)