Your C library does not check malloc returns and also malloc and free everywhere inside library functions are not the best way to write a C library.
Non-checked malloc returns - ouch, I count 12 (out of 56) without a check. Thanks for pointing this out.