I wouldn't blame malloc at all. But there might be room for performance improvement by avoiding or replacing some of these calls. Seems the code itself isn't really doing much, which I found surprising.
If you're very curious, here's the function:
https://gitlab.desy.de/thomas.white/crystfel/-/blob/master/libcrystfel/src/indexers/asdf.c?ref_type=heads#L1148