Merge change 916

* changes:
  Fix a potential integer overflow bug that could result in memory overwrites. Also add a check to the result of malloc()