diff options
author | Adrian Thurston <thurston@complang.org> | 2012-01-18 05:20:13 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-01-18 05:20:13 +0000 |
commit | 723577aa2bf3b7807d1bbbd068aaf17955faae67 (patch) | |
tree | 235b429e8e3d21a121aac2540685d762483949c0 /colm | |
parent | a9f621afb2f5c264cbd21be7202d4814d22246c8 (diff) | |
download | colm-723577aa2bf3b7807d1bbbd068aaf17955faae67.tar.gz |
Some leaks plugged.
Diffstat (limited to 'colm')
-rw-r--r-- | colm/input.c | 66 | ||||
-rw-r--r-- | colm/pdarun.h | 6 | ||||
-rw-r--r-- | colm/tree.c | 1 |
3 files changed, 41 insertions, 32 deletions
diff --git a/colm/input.c b/colm/input.c index e9a5ea7c..b6c96369 100644 --- a/colm/input.c +++ b/colm/input.c @@ -30,6 +30,9 @@ #include <assert.h> #include <unistd.h> +#define true 1 +#define false 0 + RunBuf *newRunBuf() { RunBuf *rb = (RunBuf*)malloc(sizeof(RunBuf)); @@ -37,9 +40,6 @@ RunBuf *newRunBuf() return rb; } -#define true 1 -#define false 0 - void initFdFuncs(); void initFileFuncs(); void initPatternFuncs(); @@ -57,6 +57,29 @@ void initSourceStream( SourceStream *inputStream ) inputStream->byte = 0; } +void clearSourceStream( struct ColmProgram *prg, Tree **sp, SourceStream *sourceStream ) +{ + RunBuf *buf = sourceStream->queue; + while ( buf != 0 ) { + switch ( buf->type ) { + case RunBufDataType: + break; + + case RunBufTokenType: + case RunBufIgnoreType: + case RunBufSourceType: + treeDownref( prg, sp, buf->tree ); + break; + } + + RunBuf *next = buf->next; + free( buf ); + buf = next; + } + + sourceStream->queue = 0; +} + SourceStream *newSourceStreamFile( FILE *file ) { SourceStream *is = (SourceStream*)malloc(sizeof(SourceStream)); @@ -79,17 +102,7 @@ SourceStream *newSourceStreamFd( long fd ) return is; } -RunBuf *sourceStreamHead( SourceStream *is ) -{ - return is->queue; -} - -RunBuf *sourceStreamTail( SourceStream *is ) -{ - return is->queueTail; -} - -RunBuf *sourceStreamPopHead( SourceStream *is ) +static RunBuf *sourceStreamPopHead( SourceStream *is ) { RunBuf *ret = is->queue; is->queue = is->queue->next; @@ -100,18 +113,7 @@ RunBuf *sourceStreamPopHead( SourceStream *is ) return ret; } -RunBuf *sourceStreamPopTail( SourceStream *is ) -{ - RunBuf *ret = is->queueTail; - is->queueTail = is->queue->prev; - if ( is->queueTail == 0 ) - is->queue = 0; - else - is->queueTail->next = 0; - return ret; -} - -void sourceStreamAppend( SourceStream *is, RunBuf *runBuf ) +static void sourceStreamAppend( SourceStream *is, RunBuf *runBuf ) { if ( is->queue == 0 ) { runBuf->prev = runBuf->next = 0; @@ -125,7 +127,7 @@ void sourceStreamAppend( SourceStream *is, RunBuf *runBuf ) } } -void sourceStreamPrepend( SourceStream *is, RunBuf *runBuf ) +static void sourceStreamPrepend( SourceStream *is, RunBuf *runBuf ) { if ( is->queue == 0 ) { runBuf->prev = runBuf->next = 0; @@ -334,8 +336,12 @@ void clearInputStream( struct ColmProgram *prg, Tree **sp, InputStream *inputStr break; } - buf = buf->next; + RunBuf *next = buf->next; + free( buf ); + buf = next; } + + inputStream->queue = 0; } static void inputStreamPrepend( InputStream *is, RunBuf *runBuf ) @@ -352,7 +358,7 @@ static void inputStreamPrepend( InputStream *is, RunBuf *runBuf ) } } -RunBuf *inputStreamPopHead( InputStream *is ) +static RunBuf *inputStreamPopHead( InputStream *is ) { RunBuf *ret = is->queue; is->queue = is->queue->next; @@ -380,7 +386,7 @@ static void inputStreamAppend( InputStream *is, RunBuf *runBuf ) static RunBuf *inputStreamPopTail( InputStream *is ) { RunBuf *ret = is->queueTail; - is->queueTail = is->queue->prev; + is->queueTail = is->queueTail->prev; if ( is->queueTail == 0 ) is->queue = 0; else diff --git a/colm/pdarun.h b/colm/pdarun.h index e2c0f627..15e0c3b5 100644 --- a/colm/pdarun.h +++ b/colm/pdarun.h @@ -395,9 +395,12 @@ void transferReverseCode( PdaRun *pdaRun, Tree *tree ); void initPdaRun( PdaRun *pdaRun, struct ColmProgram *prg, PdaTables *tables, FsmRun *fsmRun, int parserId, long stopTarget, int revertOn, Tree *context ); void clearPdaRun( struct ColmProgram *prg, Tree **root, PdaRun *pdaRun ); -void initInputStream( InputStream *inputStream ); +void initInputStream( InputStream *inputStream ); void clearInputStream( struct ColmProgram *prg, Tree **sp, InputStream *inputStream ); +void initSourceStream( SourceStream *in ); +void clearSourceStream( struct ColmProgram *prg, Tree **sp, SourceStream *sourceStream ); + void clearContext( PdaRun *pdaRun, Tree **sp ); Kid *extractIgnore( PdaRun *pdaRun ); @@ -440,7 +443,6 @@ long sendBackQueuedIgnore( struct ColmProgram *prg, Tree **sp, InputStream *inpu void clearIgnoreList( struct ColmProgram *prg, Tree **sp, Kid *kid ); Head *extractMatch( struct ColmProgram *prg, FsmRun *fsmRun, InputStream *inputStream ); Head *extractMatch( struct ColmProgram *prg, FsmRun *fsmRun, InputStream *inputStream ); -void initSourceStream( SourceStream *in ); void newToken( struct ColmProgram *prg, PdaRun *pdaRun, FsmRun *fsmRun ); void fsmExecute( FsmRun *fsmRun, InputStream *inputStream ); Kid *sendNamedLangEl( struct ColmProgram *prg, Tree **sp, PdaRun *pdaRun, FsmRun *fsmRun, InputStream *inputStream ); diff --git a/colm/tree.c b/colm/tree.c index 84c95b68..7602905d 100644 --- a/colm/tree.c +++ b/colm/tree.c @@ -899,6 +899,7 @@ free_tree: treeFree( prg, tree ); else if ( tree->id == LEL_ID_STREAM ) { Stream *stream = (Stream*)tree; + clearSourceStream( prg, sp, stream->in ); free( stream->in ); if ( stream->file != 0 ) fclose( stream->file ); |