8212779: ADL Parser does not check allocation return values in all cases

Made to fail gracefully in case of malloc failure.

Reviewed-by: kvn
This commit is contained in:
Jamsheed Mohammed C M 2018-11-15 21:26:35 -08:00
parent 5e0d5efe4c
commit 6c75023f1d
5 changed files with 24 additions and 13 deletions

View file

@ -1354,7 +1354,7 @@ void InstructForm::set_unique_opnds() {
// component back to an index and any DEF always goes at 0 so the
// length of the array has to be the number of components + 1.
_uniq_idx_length = _components.count() + 1;
uniq_idx = (uint*) malloc(sizeof(uint) * _uniq_idx_length);
uniq_idx = (uint*) AllocateHeap(sizeof(uint) * _uniq_idx_length);
for (i = 0; i < _uniq_idx_length; i++) {
uniq_idx[i] = i;
}
@ -3449,7 +3449,7 @@ void MatchNode::build_internalop( ) {
rstr = (_rChild) ? ((_rChild->_internalop) ?
_rChild->_internalop : _rChild->_opType) : "";
len += (int)strlen(lstr) + (int)strlen(rstr);
subtree = (char *)malloc(len);
subtree = (char *)AllocateHeap(len);
sprintf(subtree,"_%s_%s_%s", _opType, lstr, rstr);
// Hash the subtree string in _internalOps; if a name exists, use it
iop = (char *)_AD._internalOps[subtree];
@ -3863,7 +3863,7 @@ void MatchRule::matchrule_swap_commutative_op(const char* instr_ident, int count
MatchRule* clone = new MatchRule(_AD, this);
// Swap operands of commutative operation
((MatchNode*)clone)->swap_commutative_op(true, count);
char* buf = (char*) malloc(strlen(instr_ident) + 4);
char* buf = (char*) AllocateHeap(strlen(instr_ident) + 4);
sprintf(buf, "%s_%d", instr_ident, match_rules_cnt++);
clone->_result = buf;