use gt_malloc() where possible

In some places, `malloc()` was used where `gt_malloc()` could have been used. To ensure correct space calculation, these calls were replaced by `gt_malloc()` calls.