Fix multiples possible issues

- unchecked malloc return
- possible division by 0