thread/mtx_alloc: fix mtx_init handling
mtx_destructor should only called if mtx_init is successfull.
@@ -19,7 +19,7 @@ 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;
@@ -27,6 +27,8 @@ int mtx_alloc(mtx_t **mtx)
if (err)
goto out;
+ mem_destructor(m, mtx_destructor);
+
*mtx = m;
out:
