Skip to content

Commit

Permalink
Fix memory leak in the NIF post
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Aug 31, 2021
1 parent 2b4e1d2 commit f24d86e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions _posts/2015-12-05-using-c-from-elixir-with-nifs.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ db_init_conn_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
// ...and release the resource so that it will be freed when Erlang garbage collects
enif_release_resource(conn_res);

// We also need to free the memory that's not being used by the VM, otherwise
// we got a memory leak on our hands
free(conn);

return term;
}
```
Expand Down

0 comments on commit f24d86e

Please sign in to comment.