Skip to content

Commit

Permalink
thread/mtx_alloc: fix mtx_init handling
Browse files Browse the repository at this point in the history
mtx_destructor should only called if mtx_init is successfull.
  • Loading branch information
sreimers committed Jun 20, 2022
1 parent 4a5c0b4 commit 99ac986
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/thread/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ int mtx_alloc(mtx_t **mtx)
if (!mtx)
return EINVAL;

m = mem_alloc(sizeof(mtx_t), mtx_destructor);
m = mem_alloc(sizeof(mtx_t), NULL);
if (!m)
return ENOMEM;

err = mtx_init(m, mtx_plain);
if (err)
goto out;

mem_destructor(m, mtx_destructor);

*mtx = m;

out:
Expand Down

0 comments on commit 99ac986

Please sign in to comment.