Fix multuples possible issues

- unchecked malloc return
- possible division by 0