From: Tim King Date: Mon, 26 Sep 2016 03:53:23 +0000 (-0700) Subject: Freeing memory in error handling code for bounded_token_buffer. X-Git-Tag: cvc5-1.0.0~6028^2~21 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e313adf1e1d0eda70d592c771690cde496c73def;p=cvc5.git Freeing memory in error handling code for bounded_token_buffer. --- diff --git a/src/parser/bounded_token_buffer.cpp b/src/parser/bounded_token_buffer.cpp index c89005941..31a2219b9 100644 --- a/src/parser/bounded_token_buffer.cpp +++ b/src/parser/bounded_token_buffer.cpp @@ -133,70 +133,71 @@ antlr3CommonTokenDebugStreamSourceNew(ANTLR3_UINT32 hint, pANTLR3_TOKEN_SOURCE s return stream; }*/ -pBOUNDED_TOKEN_BUFFER -BoundedTokenBufferSourceNew(ANTLR3_UINT32 k, pANTLR3_TOKEN_SOURCE source) -{ - pBOUNDED_TOKEN_BUFFER buffer; - pANTLR3_COMMON_TOKEN_STREAM stream; - - - assert( k > 0 ); +pBOUNDED_TOKEN_BUFFER BoundedTokenBufferSourceNew(ANTLR3_UINT32 k, + pANTLR3_TOKEN_SOURCE source) { + pBOUNDED_TOKEN_BUFFER buffer; + pANTLR3_COMMON_TOKEN_STREAM stream; - /* Memory for the interface structure - */ - buffer = (pBOUNDED_TOKEN_BUFFER) ANTLR3_MALLOC(sizeof(BOUNDED_TOKEN_BUFFER_struct)); + assert(k > 0); - if (buffer == NULL) - { - return NULL; - } + /* Memory for the interface structure */ + buffer = + (pBOUNDED_TOKEN_BUFFER)ANTLR3_MALLOC(sizeof(BOUNDED_TOKEN_BUFFER_struct)); - buffer->tokenBuffer = (pANTLR3_COMMON_TOKEN*) ANTLR3_MALLOC(2*k*sizeof(pANTLR3_COMMON_TOKEN)); - buffer->currentIndex = 0; - buffer->maxIndex = 0; - buffer->k = k; - buffer->bufferSize = 2*k; - buffer->empty = ANTLR3_TRUE; - buffer->done = ANTLR3_FALSE; - - stream = antlr3CommonTokenStreamSourceNew(k,source); - if (stream == NULL) - { - return NULL; - } + if (buffer == NULL) { + return NULL; + } - stream->super = buffer; - buffer->commonTstream = stream; + buffer->tokenBuffer = (pANTLR3_COMMON_TOKEN*)ANTLR3_MALLOC( + 2 * k * sizeof(pANTLR3_COMMON_TOKEN)); + if (buffer->tokenBuffer == NULL) { + ANTLR3_FREE(buffer); + return NULL; + } - /* Defaults - */ - stream->p = -1; + buffer->currentIndex = 0; + buffer->maxIndex = 0; + buffer->k = k; + buffer->bufferSize = 2 * k; + buffer->empty = ANTLR3_TRUE; + buffer->done = ANTLR3_FALSE; + + stream = antlr3CommonTokenStreamSourceNew(k, source); + if (stream == NULL) { + ANTLR3_FREE(buffer->tokenBuffer); + ANTLR3_FREE(buffer); + return NULL; + } - /* Install the token stream API - */ - stream->tstream->_LT = tokLT; - stream->tstream->get = get; - stream->tstream->getTokenSource = getTokenSource; - stream->tstream->setTokenSource = setTokenSource; - stream->tstream->toString = toString; - stream->tstream->toStringSS = toStringSS; - stream->tstream->toStringTT = toStringTT; - stream->tstream->setDebugListener = setDebugListener; - - /* Install INT_STREAM interface - */ - stream->tstream->istream->_LA = _LA; - stream->tstream->istream->mark = mark; - stream->tstream->istream->release = release; - stream->tstream->istream->size = size; - stream->tstream->istream->index = tindex; - stream->tstream->istream->rewind = rewindStream; - stream->tstream->istream->rewindLast= rewindLast; - stream->tstream->istream->seek = seek; - stream->tstream->istream->consume = consume; - stream->tstream->istream->getSourceName = getSourceName; - - return buffer; + stream->super = buffer; + buffer->commonTstream = stream; + + /* Defaults */ + stream->p = -1; + + /* Install the token stream API */ + stream->tstream->_LT = tokLT; + stream->tstream->get = get; + stream->tstream->getTokenSource = getTokenSource; + stream->tstream->setTokenSource = setTokenSource; + stream->tstream->toString = toString; + stream->tstream->toStringSS = toStringSS; + stream->tstream->toStringTT = toStringTT; + stream->tstream->setDebugListener = setDebugListener; + + /* Install INT_STREAM interface */ + stream->tstream->istream->_LA = _LA; + stream->tstream->istream->mark = mark; + stream->tstream->istream->release = release; + stream->tstream->istream->size = size; + stream->tstream->istream->index = tindex; + stream->tstream->istream->rewind = rewindStream; + stream->tstream->istream->rewindLast = rewindLast; + stream->tstream->istream->seek = seek; + stream->tstream->istream->consume = consume; + stream->tstream->istream->getSourceName = getSourceName; + + return buffer; } // Install a debug listener adn switch to debug mode methods