Skip to content

Commit

Permalink
de-allocate entry via enif_free() when name allocation fails
Browse files Browse the repository at this point in the history
In the event that an entry could be allocated, but the name allocation
for the entry fails, free the entry with enif_free().

While updating Erlang on Gentoo I noticed the following compiler
warning:

c_src/mqtree.c:208:5: warning: ‘free’ called on pointer returned from
a mismatched allocation function [-Wmismatched-dealloc]

I'm not familiar with erl_nif, but it looks like this is a legitimate
warning and the memory should be freed via the enif_free() interface.
  • Loading branch information
jeremycline committed May 26, 2023
1 parent b87975f commit d283e5c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion c_src/mqtree.c
Expand Up @@ -205,7 +205,7 @@ int register_tree(char *name, state_t *state) {

entry->name = enif_alloc(strlen(name) + 1);
if (!entry->name) {
free(entry);
enif_free(entry);
return ENOMEM;
}

Expand Down

0 comments on commit d283e5c

Please sign in to comment.